Set newTimer() with newVar()

PennController for IBEX Forums Support Set newTimer() with newVar()

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #5969
    new2ibex
    Participant

    Hi:

    I am designing an experiment on PCIbex in which I need to calibrate the user’s average response time in the first 15 trials in order to know if they are responding too slow in later trials. I keep the average response time in a newVar(). But I could not find a way to get that value into the newTimer(). Is there a way to do this?

    Thanks!

    #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

    #5988
    new2ibex
    Participant

    Thank you so much! Your code works perfectly.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.