Page 1 of 1

Toggle timer on/off

Posted: Sun May 02, 2021 4:23 am
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.

Re: Toggle timer on/off

Posted: Sun May 02, 2021 6:41 am
by TheyCallMeTim13
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.