require help with my ticktimer script to button

Post Reply
energyau
Posts: 5
Joined: Mon Jun 12, 2017 9:55 am

require help with my ticktimer script to button

Post 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:
Code: [show] | [select all] lua
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
Code: [show] | [select all] lua
reset_ticktimer()
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
Last edited by energyau on Tue Jun 13, 2017 10:26 am, edited 1 time in total.

User avatar
SlySven
Posts: 1023
Joined: Mon Mar 04, 2013 3:40 pm
Location: Deepest Wiltshire, UK
Discord: SlySven#2703

Re: require help with my ticktimer script to button

Post 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...}

energyau
Posts: 5
Joined: Mon Jun 12, 2017 9:55 am

Re: require help with my ticktimer script to button

Post 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

Post Reply