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 


Destroy all timers

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Frouk
Master Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 489
Location: mov dword ptr [Ukraine]

PostPosted: Tue Jul 27, 2021 6:44 am    Post subject: Destroy all timers Reply with quote

Is there's lua command that allows to destroy all timers?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Tue Jul 27, 2021 7:11 am    Post subject: Reply with quote

No. It's your responsibility to keep track of them
_________________
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
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1055
Location: 0x90

PostPosted: Tue Jul 27, 2021 7:13 am    Post subject: Reply with quote

In short, no. You have to manually destroy the timer objects, it's usually done in the logic of the function that determines whether the timer should continue or not.

Or you could use this function instead:
Code:

createTimer(delay, function(...),...):
  Creates a timer object that waits the given delay, executes the given function, and then self-destructs
Back to top
View user's profile Send private message
ByTransient
Expert Cheater
Reputation: 5

Joined: 05 Sep 2020
Posts: 240

PostPosted: Tue Jul 27, 2021 8:44 am    Post subject: Reply with quote

Maybe a solution can be provided with an arrangement.
Some requirements:
1) The created Timer should follow each other's order (tim1-tim2-tim3 etc.)
2) While creating the Timer, an existing function must be ready and this assignment must be made during creation (tim3.OnTimer=yourTim3Function)
3) The render function and the function of the key that killed it should be at the bottom of the Script code.

Here is the code sample;
Code:
local allTimer={ }

local timerCrtNil=1

function TimerNil()
for i=0, 3 do
allT=allTimer["myT"..i+1]
if allT then
allT.Destroy() allT=nil end
end
end
--Must always be dead at the entrance
TimerNil()

--script code
--...
--...

function TimerCreate()
allTimer.myT2=createTimer() allTimer.myT2.Interval=1000 allTimer.myT2.Enabled=false
allTimer.myT2.OnTimer=myT2Tick
allTimer.myT3=createTimer() allTimer.myT3.Interval=2000 allTimer.myT3.Enabled=false
allTimer.myT3.OnTimer=myT3Tick
allTimer.myT1=createTimer() allTimer.myT1.Interval=1000 allTimer.myT1.Enabled=true
allTimer.myT1.OnTimer=myT1Tick
allTimer.myT4=createTimer() allTimer.myT4.Interval=2000 allTimer.myT4.Enabled=false
allTimer.myT4.OnTimer=myT4Tick
end

--button timer create or nil function
function timerOpsion()
if timerCrtNil==1 then
TimerCreate()
timerCrtNil=2
else
TimerNil()
timerCrtNil=1
end
end

--UDF1.CEButton1.OnClick=timerOpsion


Here is a test example;
Code:
local allTimer={ }

function TimerNil()
for i=0, 3 do
allT=allTimer["myT"..i+1]
if allT then
allT.Destroy() allT=nil end
end
end
--Must always be dead at the entrance
TimerNil()

local aa=0
local timerCrtNil=1

function myT2Tick()
aa=tonumber(aa) + 1
print("myT2 Tick: "..aa)
if aa==10 then
allTimer.myT2.Enabled=false
end
end

function myT1Tick()
aa=tonumber(aa) + 1
print("myT1 Tick: "..aa)
if aa==10 then
TimerNil()
--check nil?
--allTimer.myT2.Enabled=true --result: "Error:Access violation"
--or create check
--allTimer.myT2=createTimer() allTimer.myT2.Interval=1000 allTimer.myT2.OnTimer=myT2Tick aa=0 allTimer.myT2.Enabled=true
end
end

--script code
--...
--...

function TimerCreate()
aa=0
allTimer.myT2=createTimer() allTimer.myT2.Interval=1000 allTimer.myT2.Enabled=false
allTimer.myT2.OnTimer=myT2Tick
allTimer.myT3=createTimer() allTimer.myT3.Interval=2000 allTimer.myT3.Enabled=false
allTimer.myT3.OnTimer=myT3Tick
allTimer.myT1=createTimer() allTimer.myT1.Interval=1000 allTimer.myT1.Enabled=true
allTimer.myT1.OnTimer=myT1Tick
allTimer.myT4=createTimer() allTimer.myT4.Interval=2000 allTimer.myT4.Enabled=false
allTimer.myT4.OnTimer=myT4Tick
end

--button timer create or nil function
function timerOpsion()
if timerCrtNil==1 then
TimerCreate()
timerCrtNil=2
else
TimerNil()
timerCrtNil=1
end
end

timerOpsion()
--UDF1.CEButton1.OnClick=timerOpsion


Enjoy it!
Back to top
View user's profile Send private message
Frouk
Master Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 489
Location: mov dword ptr [Ukraine]

PostPosted: Tue Jul 27, 2021 2:46 pm    Post subject: Reply with quote

Thanks for help!
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