 |
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
etioplmld Advanced Cheater
Reputation: 0
Joined: 09 Feb 2021 Posts: 76
|
Posted: Tue May 23, 2023 11:08 pm Post subject: About createTimer Functions |
|
|
Code: |
function countdown()
print(1)
end
local cctimer = createTimer()
cctimer.Interval = 1000
cctimer.OnTimer = countdown
|
This code will output a 1 per second,Why does this code not output
1 ,1 2 , 123 ....,It seems to have created many timers
Code: |
for i=1,5 do
createTimer(1000*i,function() print(i) end )
end
|
Can ce create two timers at the same time, Start one second after another starts.Two counts timer like this?
Code: |
local cctimer = createTimer()
cctimer.Interval = 1000
i = 0
function countdown()
i=i + 1
print(i)
if i>= 5 then
object_destroy(cctimer)
end
end
cctimer.OnTimer = countdown
function countdown()
local i = 0
local t = createTimer()
t.Interval = 1000
t.OnTimer = function()
i = i + 1
print(i)
if i>=5 then
t.Destroy()
end
end
end
countdown()
|
|
|
Back to top |
|
 |
LeFiXER Grandmaster Cheater Supreme
Reputation: 20
Joined: 02 Sep 2011 Posts: 1066 Location: 0x90
|
Posted: Wed May 24, 2023 4:58 am Post subject: Re: About createTimer Functions |
|
|
etioplmld wrote: |
Code: |
function countdown()
print(1)
end
local cctimer = createTimer()
cctimer.Interval = 1000
cctimer.OnTimer = countdown
|
This code will output a 1 per second,Why does this code not output
1 ,1 2 , 123 ....,It seems to have created many timers
|
You have no check to see if the timer exists.
Code: |
if cctimer then cctimer.destroy(); cctimer = nil end
|
etioplmld wrote: |
Code: |
for i=1,5 do
createTimer(1000*i,function() print(i) end )
end
|
|
This loops and creates a timer with each loop iteration, setting the interval to 1,000 milliseconds multiplied by the iterator. With every timer tick it prints the iterator number.
etioplmld wrote: |
Can ce create two timers at the same time, Start one second after another starts.Two counts timer like this?
Code: |
local cctimer = createTimer()
cctimer.Interval = 1000
i = 0
function countdown()
i=i + 1
print(i)
if i>= 5 then
object_destroy(cctimer)
end
end
cctimer.OnTimer = countdown
function countdown()
local i = 0
local t = createTimer()
t.Interval = 1000
t.OnTimer = function()
i = i + 1
print(i)
if i>=5 then
t.Destroy()
end
end
end
countdown()
|
|
I am not entirely sure of the limitation of how many timers that can be created at any one-time; however, I know that it's possible to create several. I think the limitation is based on the amount of threads that your processor can handle although I could be wrong about that.
I would achieve what you want by doing this:
Code: |
-- First and foremost, check if the components exist already
if t1 then t1.destroy(); t1 = nil end
if t2 then t2.destroy(); t2 = nil end
-- Variable to store the timer component so that the timers can be children of Cheat Engine
local owner = getMainForm()
-- Variable to store count
local count = 0
-- Initiate timer variables
local t1,t2 = createTimer(owner),createTimer(owner, false)
-- Set interval
t1.Interval = 1000
t2.Interval = 1000
-- Set function based on timer tick
t1.OnTimer = function()
count = count + 1
print('Timer1 Iterator:\t' .. count)
if count == 2 then
t2.Enabled = true
elseif count >= 5 then
t1.destroy()
t1 = nil
count = nil
end
end
t2.OnTimer = function()
print('Timer2 intitiated')
t2.destroy()
t2 = nil
end
|
I'm not sure why you want this, but it achieves what you requested. |
|
Back to top |
|
 |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
|
Back to top |
|
 |
|
|
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
|
|