Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


program crashed after clicking on "Execute Script"

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
bakimo
How do I cheat?
Reputation: 0

Joined: 16 Dec 2024
Posts: 2

PostPosted: Mon Dec 16, 2024 8:43 am    Post subject: program crashed after clicking on "Execute Script" Reply with quote

The program crashed after clicking on "Execute Script" in the Lua script.
I think the issue is with my script since I'm a beginner. Could someone take a look?

The script :----------------------------------------------------------------
local iterations = 2000

local oldValue = 1.8387342534
local newValue = -20000

local valueType = vtFloat

local targetAddress = getAddress("game.exe+33F00C9")

function searchAndReplace()
local currentValue = readFloat(targetAddress)
if currentValue == oldValue then
writeFloat(targetAddress, newValue)
print(string.format("DONE %X: %f -> %f", targetAddress, oldValue, newValue))
else
print("FALSE!")
end
end

for i = 1, iterations do
searchAndReplace()
sleep(10000)
end

print("ALL DONE!")

--------------------------------------------------------------------

Thanks
Back to top
View user's profile Send private message Send e-mail
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4702

PostPosted: Mon Dec 16, 2024 12:36 pm    Post subject: Reply with quote

The main thread runs the Lua script. You're blocking the main thread for at least 2000*10000ms, or about 5 and a half hours. The main thread is also responsible for handling GUI events. While it's blocked, it can't do that, so it will appear as if CE has crashed.

Use asynchronous events, such as a timer:
Code:
local iterations = 2000

local oldValue = 1.8387342534
local newValue = -20000

local valueType = vtFloat

local targetAddress = getAddress("game.exe+33F00C9")

function searchAndReplace()
  local currentValue = readFloat(targetAddress)
  if currentValue == oldValue then
    writeFloat(targetAddress, newValue)
    print(string.format("DONE %X: %f -> %f", targetAddress, oldValue, newValue))
  else
    print("FALSE!")
  end
end

local t = createTimer()
t.Interval = 10000
t.OnTimer = function(t)
  if iterations > 0 then
    iterations = iterations - 1
  else
    print("ALL DONE!")
    t.destroy()
    return
  end

  searchAndReplace()
end

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
bakimo
How do I cheat?
Reputation: 0

Joined: 16 Dec 2024
Posts: 2

PostPosted: Wed Dec 18, 2024 3:24 am    Post subject: Reply with quote

ParkourPenguin wrote:
The main thread runs the Lua script. You're blocking the main thread for at least 2000*10000ms, or about 5 and a half hours. The main thread is also responsible for handling GUI events. While it's blocked, it can't do that, so it will appear as if CE has crashed.[/code]


Thanks for the explanation

I'll try it
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites