Knob to change ms of a Timer
-
Hello, I have this Timer that activates and deactivates a Button. Now I want a Knob to change the ms of the Timer like from 0,1sec to 10sec?
const var Timer = Engine.createTimerObject(); Timer.setTimerCallback(function() { if (Content.getComponent("Button1").getValue() == 0) { Content.getComponent("Button1").setValue(1); } else { Content.getComponent("Button1").setValue(0); } }); Timer.startTimer(5000);
-
@treynterrio said in Knob to change ms of a Timer:
if (Content.getComponent("Button1").getValue() == 0) { Content.getComponent("Button1").setValue(1); } else { Content.getComponent("Button1").setValue(0); }
What is this supposed to do?
To change the duration you just call
startTimer()
again from your knob's callback -
@d-healey this is for the Button this function works but I want to change the ms from the timer its set to 5000 so its fixed but I want to control it
-
@treynterrio Ah I see. You should store the reference to the button in on init rather than creating a new reference every time you want to access it.
You can also condense the script.
const Button1 = Content.getComponent("Button1"); Timer.setTimerCallback(function() { Button1.setValue(!Button1.getValue()); });
-
@d-healey ok. but how can I make a knob that controls the ms between the Button is activated and deactivated?
-
@treynterrio Like I said, use
startTimer()
again to change the duration from within your knob's callback. -
@d-healey I'm using this:
inline function ontimeControl(component, value) { Timer.startTimer(value); }; Content.getComponent("time").setControlCallback(ontimeControl);
and it works but I got an error in the console every time I change the value with the knob.
Interface:! Line 30, column 18: Go easy on the timer
-
@treynterrio Don't go below 40ms
-
@d-healey now it works! thanks for your time and help
-
It'll take 10ms but you can easily choke the message threat of you're repainting a big surface and using blur.
Also older CPUs might complain. VMs too.