View previous topic :: View next topic |
Author |
Message |
Razi Expert Cheater
Reputation: 1
Joined: 17 Jan 2018 Posts: 180
|
Posted: Tue Mar 28, 2023 7:23 am Post subject: What is the best way to create a timer? |
|
|
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 |
|
 |
Dark Byte Site Admin
Reputation: 448
Joined: 09 May 2003 Posts: 24880 Location: The netherlands
|
Posted: Tue Mar 28, 2023 7:40 am Post subject: |
|
|
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 |
|
 |
Razi Expert Cheater
Reputation: 1
Joined: 17 Jan 2018 Posts: 180
|
Posted: Tue Mar 28, 2023 8:17 am Post subject: |
|
|
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 |
|
 |
Dark Byte Site Admin
Reputation: 448
Joined: 09 May 2003 Posts: 24880 Location: The netherlands
|
Posted: Tue Mar 28, 2023 8:44 am Post subject: |
|
|
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 |
|
 |
Razi Expert Cheater
Reputation: 1
Joined: 17 Jan 2018 Posts: 180
|
Posted: Tue Mar 28, 2023 7:17 pm Post subject: |
|
|
Dark Byte wrote: | createTimer(interval,function) runs the given function one time |
Didn't know that, thanks.
|
|
Back to top |
|
 |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1664
|
Posted: Wed Mar 29, 2023 1:02 am Post subject: |
|
|
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 |
|
 |
|