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 


What is the best way to create a timer?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Razi
Expert Cheater
Reputation: 1

Joined: 17 Jan 2018
Posts: 202

PostPosted: Tue Mar 28, 2023 7:23 am    Post subject: What is the best way to create a timer? Reply with quote

I have a few questions about the timer:
1) What is the best way to create a timer? Need code examples.
2) What is better, create a timer with code or create a timer in a form designer? Is there a difference between these methods?
3) Is the local timer somehow better than the global one or faster?

4) How to make it so that after executing the code in the lua engine, display/print the execution time of the code?
5) And also display/print the amount of memory used by the code. For code optimization.


Last edited by Razi on Tue Mar 28, 2023 8:18 am; edited 1 time in total
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

Joined: 09 May 2003
Posts: 25262
Location: The netherlands

PostPosted: Tue Mar 28, 2023 7:40 am    Post subject: Reply with quote

1: Does the timer run repeatedly or only 1 time?

you can put it on the form or create it from lua code.
createTimer(interval,function) runs the given function one time

x=createTimer()
x.Interval=interval
x.OnTimer=function

runs the function every interval milliseconds

2: no difference. Except that the formdesigner calls a global function and code created ones can use local functions

3: not really

4: use getTickCount() when the code starts and stops to get the current time, and the difference between the two is the time the code took

5: not possible for your code specifically but you can call collectgarbage("count") to get the amount of memory used

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Razi
Expert Cheater
Reputation: 1

Joined: 17 Jan 2018
Posts: 202

PostPosted: Tue Mar 28, 2023 8:17 am    Post subject: Reply with quote

Dark Byte wrote:
1: Does the timer run repeatedly or only 1 time?
Timer runs repeatedly.
Code:
timer.Interval = 1000

Dark Byte wrote:
5: not possible for your code specifically but you can call collectgarbage("count") to get the amount of memory used

Can I call collectgarbage("count") every 1 second?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

Joined: 09 May 2003
Posts: 25262
Location: The netherlands

PostPosted: Tue Mar 28, 2023 8:44 am    Post subject: Reply with quote

yes you can call it every second.
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Razi
Expert Cheater
Reputation: 1

Joined: 17 Jan 2018
Posts: 202

PostPosted: Tue Mar 28, 2023 7:17 pm    Post subject: Reply with quote

Dark Byte wrote:
createTimer(interval,function) runs the given function one time

Didn't know that, thanks.
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Wed Mar 29, 2023 1:02 am    Post subject: Reply with quote

Code:
local function printMemUsage()
      local memUsed = (collectgarbage("count")) / 1000
      print("\n---------MEMORY USAGE INFORMATION---------")
    print("System Memory Used:", string.format("%.03f", memUsed), "Mb")
    print("------------------------------------------\n")
    return true
end

local i = 0

function test()
 timer.Enabled = true
 i = i + 1
 if i > 4 then
  timer.Enabled = false
 end
 print("Passed #"..i)
 printMemUsage()
end

timer = createTimer(true)
timer.Interval = 1000
timer.Enabled = false
timer.OnTimer = test

test()

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
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