Posted: Thu Jun 16, 2022 11:03 am Post subject: Continuous loop question
Hey, I'm trying to create a LUA script that releases a button that I'm holding when a float address value reaches >0.
I can read the value with readFloat and keyUp() helps to release the button.
The problem is that I can only run it either once or the lua engine takes window priority after keyup().
I would obviously wish to stay in the game and once the float's value again reaches >0 keyup would actuate again.
How can I read the float value continuously (chosen interval such as 10 or 100ms etc so things don't freeze) and have the code press keyUp every time float value exceeds setpoint?
Thank you.
Unfortunately the code doesn't work at all unless I add the print(a) line. And if I do, the code kind of works but cheat engine window will be opened (lua engine).
Edit: I guess I get the feeling of it working then is cause window redirects to CE and thus the numpad button is not considered to be pressed anymore
Code:
if t then t.destroy(); t = nil end
t = createTimer()
t.Interval = 10
t.OnTimer = function()
a = readFloat("7FF44048098C")
if a > 0 then
print(a)
keyUp(VK_NUMPAD7)
end
end
The address "7FF44048098C" might change each time the game is run
`a` should be local
`print(a)` does nothing but output the float to the Lua console (maybe changing window focus does something?)
Your code isn't indented properly
If that's an AA script and not a Lua script, you should be using {$lua} blocks and put the correct code under [ENABLE] and [DISABLE]
Maybe it's keyUp that's not working for you? Or maybe keyUp should only be called once each time the condition is true, then wait until it's false before allowing to be called again? _________________
I don't know where I'm going, but I'll figure it out when I get there.
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