Posted: Mon Nov 07, 2022 9:33 pm Post subject: Lua Script I made freezes Cheat Engine while running
Hi!
I don't know much of scripting, but I was trying to make a script to log the RNG and it works.
The problem is that while the scrip is running Cheat Engine (7.4) freezes, my script only stops running when I close the game, and only then Cheat Engine resumes to work.
I couldn't find anything upon search that could fix this issue, maybe because I still naive into scripting/CE and things like this. Can I be helped out? thx
Code:
local number1 = readInteger("ePSXe.exe+A8B030")
showMessage(number1)
file = io.open("J:/RNG_Log.txt", "a")
date = os.date(" Session: %d/%m/%Y - %X")
file:write(date, "\n")
::loop::
local function isempty(s)
return s == nil or s == ''
end
if isempty(number1) then
goto fim
end
number2 = readInteger("ePSXe.exe+A8B030")
if (number1 ~= number2) then
file:write(number1, "\n")
sleep(100)
number1 = number2
goto loop
return
end
sleep(100)
goto loop
::fim::
io.close(file)
return
Anyway, Lua code is run in the main thread by default. Only the main thread is allowed to access the GUI. If you block the main thread (i.e. via `sleep`), the GUI stops working.
Don't use goto- Lua isn't an assembly language. Use things like if...elseif...else, for, while, etc. Only use goto if one of these can't solve your problem. e.g. Lua has `break` but not `continue` for `for` loops
You shouldn't keep a file handle open for longer than you need to. You probably don't need to keep it open all the time in this case.
A timer would probably be the easiest way of doing this. Example:
Code:
local function logval(...)
local file = assert(io.open('J:/RNG_Log.txt', 'a'))
assert(file:write(...))
file:close()
end
local oldval = readInteger('ePSXe.exe+A8B030')
if not oldval then return end
logval(os.date(' Session: %d/%m/%Y - %X\n'), oldval, '\n')
if valLogTimer then valLogTimer.destroy() end
valLogTimer = createTimer()
valLogTimer.Interval = 100
valLogTimer.OnTimer = function(t)
local newval = readInteger('ePSXe.exe+A8B030')
if not newval then
t.Enabled = false
return
end
if oldval ~= newval then
oldval = newval
logval(newval, '\n')
end
end
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