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 


Need help with lua timer toggle script

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

Joined: 06 Mar 2021
Posts: 4

PostPosted: Sat Mar 06, 2021 4:33 am    Post subject: Need help with lua timer toggle script Reply with quote

hi, i have two scripts, how do i make them switch to each other every 5 second?
like first 5 second the script 1 will be on, then next 5 second script 1 turn off and script 2 turn on, 5 second again script 1 turn on and script 2 turn off...

im sorry im newbie and dont know how to make it so i need some help Very Happy
Back to top
View user's profile Send private message
ByTransient
Expert Cheater
Reputation: 5

Joined: 05 Sep 2020
Posts: 240

PostPosted: Sat Mar 06, 2021 6:39 am    Post subject: Reply with quote

Code:
if ftimer then ftimer.destroy() ftimer=nil end
ftimer=createTimer()
ftimer.Interval=1000 ftimer.Enabled=false

local tIndx=0
local fIndx=1

ftimer.OnTimer=function()
tIndx=tonumber(tIndx) + 1
--print(tIndx)
if tIndx==5 then
if fIndx==1 then
print("function "..fIndx.." active") --your function 1
fIndx=2
tIndx=0
else
print("function "..fIndx.." active") --your function 2
fIndx=1
tIndx=0
end
end
end
Back to top
View user's profile Send private message
Lynxz Gaming
Expert Cheater
Reputation: 4

Joined: 01 Jul 2017
Posts: 208
Location: help

PostPosted: Sat Mar 06, 2021 7:39 am    Post subject: Re: Need help with lua timer toggle script Reply with quote

or other solution
Code:

if timer then timer.destroy() end -- if timer is exists then destroy it (so theres no duplicate timer)
timer = createTimer() -- create a timer
timer.interval = 5000 -- execute ontimer event every 5 seconds
timer.enabled = true  -- start the timer

local switch = 0 -- a switch variable for specific script to be executed

timer.ontimer = function() -- ontimer event that execute every 5 sec
  if switch == 0 then
    switch = 1 -- if switch is 0 then it change to 1 and execute the first script
    print("first script")

  elseif switch == 1 then
    switch = 0 -- if switch is 1 then it change to 0 and execute the second script
    print("second script")

  end
end

_________________
my english is bad
discord : rynx#9828
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
oazumi29
How do I cheat?
Reputation: 0

Joined: 06 Mar 2021
Posts: 4

PostPosted: Tue Mar 09, 2021 5:20 am    Post subject: Reply with quote

thank you guys!
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