Toggle timer on/off

Want Cheat Engine to do something specific and no idea how to do that, ask here. (From simple scripts to full trainers and extensions)
Post Reply
0dijm1md
What is cheating?
What is cheating?
Posts: 1
Joined: Sun May 02, 2021 4:15 am
Reputation: 0

Toggle timer on/off

Post by 0dijm1md »

I'm trying to have a toggle button attached to a timer.

Code: Select all

Val = 0
function CETrainer_CEToggleBox1Click(sender)
local timer = createTimer(getMainForm())
timer.Interval = 1000
timer.OnTimer = function(timer)
writeInteger("Castles.exe+311B0A", 120)
writeInteger("Catles.exe+311D0D", 120)
sleep(100)
writeInteger("Castles.exe+311B0A", 0)
writeInteger("Castles.exe+311D0D", 0)
end
if (Val == 0) then
    DoneState = false
    Val = 1
  else
    DoneState = true
   Val  = 0
  end
   if DoneState == true then
    timer.destroy()
  end
end
end


But when I toggle on the script the timer runs once, and then stops. I want it to run continuously until the button toggle is turned off. I don't make trainers very often, so any code help would be appreciated.

TimFun13
Expert Cheater
Expert Cheater
Posts: 1353
Joined: Fri Mar 03, 2017 12:31 am
Reputation: 7

Re: Toggle timer on/off

Post by TimFun13 »

Loading this script.

Code: Select all

Val = 0
function CETrainer_CEToggleBox1Click(sender)
	local timer = createTimer(getMainForm())
	timer.Interval = 1000
	timer.OnTimer = function(timer)
		-- writeInteger("Castles.exe+311B0A", 120)
		-- writeInteger("Catles.exe+311D0D", 120)
		print(1)
		sleep(100)
		-- writeInteger("Castles.exe+311B0A", 0)
		-- writeInteger("Castles.exe+311D0D", 0)
		print(2)
	end
	if (Val == 0) then
		DoneState = false
		Val = 1
	else
		DoneState = true
		Val  = 0
	end
	if DoneState == true then
		timer.destroy()
	end
end

And running this creates a continuous timer, but if you rerun the function it just keeps creating new timers.

Code: Select all

CETrainer_CEToggleBox1Click()

So it might be a problem with the addresses, you might try and read from them and print the value to see if that works. And you need to check "timer" for nil and create a timer based on that, so you can disable the timer.

EDIT: And you have an extra trailing END, I assume it's from a larger script.

Post Reply

Who is online

Users browsing this forum: No registered users