Page 1 of 1
require help with my ticktimer script to button
Posted: Mon Jun 12, 2017 10:37 am
by energyau
I want to make a button that turns on a command.
The command then repeats it self every 60 secs.
then I want to make a button that turns it off.
so far i have this. I just don't know how to turn it off
the script is:
local ticktimer
function reset_ticktimer()
if ticktimer then
killTimer(ticktimer)
end
ticktimer = tempTimer(1, function() increment_ticktimer(60) end)
end
function increment_ticktimer(time_left)
time_left = time_left - 1
if time_left == 40 then
send("break wall")
elseif time_left == 0 then
reset_ticktimer()
return
end
ticktimer = tempTimer(1, function() increment_ticktimer(time_left) end)
end
the button is
works well when i click button. But have no idea how to turn it off with another button. or can i use same button to turn off and on that changes red/green to say if its off or on?
any ideas?
Thanks
Re: require help with my ticktimer script to button
Posted: Tue Jun 13, 2017 1:39 am
by SlySven
You can use a "Button" on a toolbar that can have two "states" if you set it to be a push-down one and you can read the state with the getButtonState() command that will return 1 or 2 depending on whether the button is "off" or "on" but only within the lua script for THAT button in the editor...
The people who favour "labels" will probably tell you a way to produce the same effect using the setLabelReleaseCallback("labelName", "eventName",...) which will send an "event" of type "eventName" with any arguments after that to an event handler (lua function in a "Script" that has the same name as the "Script" and is set to receive events of that name) when the specified "label" is left-clicked with the mouse and then the mouse button is released over it. {There are also setLabelClickCallback/setLabelOnEnter/setLabelOnLeave, with the same form but interact differently as their names suggest...}
Re: require help with my ticktimer script to button
Posted: Tue Jun 13, 2017 10:11 am
by energyau
ok thanks a lot of that.
Any chance you could show me how how to change the botton to do the above command then how to turn the timmer off with button pressed off?
thanks