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 


Continuous loop question

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

Joined: 16 Jun 2022
Posts: 2

PostPosted: Thu Jun 16, 2022 11:03 am    Post subject: Continuous loop question Reply with quote

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.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4297

PostPosted: Thu Jun 16, 2022 12:11 pm    Post subject: Reply with quote

Use a timer.

Code:
if t then t.destroy(); t = nil end
t = createTimer()
t.Interval = 50
t.OnTimer = function()
  if readFloat(address) > 0 then
    keyUp(...)
  end
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
JapeL
How do I cheat?
Reputation: 0

Joined: 16 Jun 2022
Posts: 2

PostPosted: Thu Jun 16, 2022 12:43 pm    Post subject: Reply with quote

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 Very Happy

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

[ENABLE]
[DISABLE]
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4297

PostPosted: Thu Jun 16, 2022 12:55 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
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