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 


using timer on Lua Engine

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

Joined: 15 Dec 2019
Posts: 3

PostPosted: Mon Dec 23, 2019 7:44 pm    Post subject: using timer on Lua Engine Reply with quote

I have an script where I am exctracting an Adress. after that, I want to check the same adress until this change to a new value and continue with my script.

this is my example.

Code:
-- My script where I find the Adress.

MyAdress = -- adress

Value = readDouble(MyAdress)

while true do
  New_Value = readDouble(MyAdress) 
  if ( New_Value ~= Value ) then
    Value = New_Value
    break
  end
end

-- continue my scrip...


the problem is if the value take a lot of time to change, the CE have issues like "not responding" and this happened even if I put a sleep in the loop, I tried to use timer in lua instead to use while loop. but the problem is, the timer start when the whole script is finished. for example.

Code:
-- My script where I find the Adress.

MyAdress = -- adress
Value = readDouble(MyAdress)
timer = createTimer(MainForm,true)
timer.Interval = 100

timer.OnTimer = function(timer)
  New_Value = readDouble(MyAdress)
  if New_Value ~= Value then
     Value = New_Value
     timer.destroy()
  end
end


Code:
-- Continue my script

print('The new value is --> ',Value)


And this timer is working well ending with a new value, but the problem is first the final print is execute, and after that, the timer. I only have some days with lua language, I am still learning. maybe I am not using the timer really well. Any correction on my script I would apreciate. Smile

_________________
I would like to improve my level of hackng programs.
Back to top
View user's profile Send private message
DaSpamer
Grandmaster Cheater Supreme
Reputation: 52

Joined: 13 Sep 2011
Posts: 1578

PostPosted: Wed Dec 25, 2019 9:40 am    Post subject: Reply with quote

The reason is, that the code is running continuously in the main thread, thus it cannot proceed and handle other events until it's out of the loop.

On solution is to insert in your loop (while true do ... end);
The following command,
Code:
processMessages();

So C.E would continue to handle messages and won't go unresponsive.

But doing such loop is quite intensive and unnecessary (for this kind of task), so using a timer is much better solution.
Which bring us to the next solution;
Another simple solution is to place the rest of the script inside a function, and from the timer object call it.
Code:
MyAdress = -- adress
Value = readDouble(MyAdress)
timer = createTimer(MainForm,true)
timer.Interval = 100

timer.OnTimer = function(timer)
  New_Value = readDouble(MyAdress)
  if New_Value ~= Value then
     Value = New_Value
     timer.destroy();
     ContinueScript();
  end
end   


function ContinueScript(...)
   print('The new value is --> ',Value)
end

_________________
HEY Hitler
Do you get lazy when making trainers?
Well no more!
My CETrainer will generate it for you in seconds, so you won't get lazy! Very Happy

http://forum.cheatengine.org/viewtopic.php?t=564919
Back to top
View user's profile Send private message
crisian789
How do I cheat?
Reputation: 0

Joined: 15 Dec 2019
Posts: 3

PostPosted: Wed Dec 25, 2019 6:58 pm    Post subject: Reply with quote

OH Shocked So cool! thank you for the correction Very Happy ,
I will use the timer, seems more stable.

_________________
I would like to improve my level of hackng programs.
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 Tutorials 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