Reply To: Set newTimer() with newVar()

PennController for IBEX Forums Support Set newTimer() with newVar() Reply To: Set newTimer() with newVar()

#5970
Jeremy
Keymaster

Hi,

That’s a need I hadn’t anticipated, though it makes total sense that some designs would need that.

Add this at the top of your script, below PennController.ResetPrefix(null):

_AddStandardCommands(function(PennEngine){
    this.actions = {
        duration: function(resolve, duration){
            const nduration = Number(duration);
            if (isNaN(nduration) || nduration < 0)
                PennEngine.debug.error("Invalid duration for timer "+this.id+" (&quot;"+duration+"&quot;)");
            else
                this.duration = nduration;
            resolve();
        }
    }
});

Then you can use the command .duration to (re)set the duration of your Timer, for example:

newTrial(
    newVar("duration")
    ,
    newTextInput("input","Enter a duration in ms").print().wait().remove().setVar("duration")
    ,
    newTimer("timeout",1).duration( getVar("duration") ).start().wait()
    ,
    newText("Timeout elapsed").print()
    ,
    newButton().wait()
)

Jeremy