Posted: Mon Dec 16, 2024 8:43 am Post subject: program crashed after clicking on "Execute Script"
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
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.
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]
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