Variable Updating

PennController for IBEX Forums Support Variable Updating

Tagged: 

This topic contains 3 replies, has 2 voices, and was last updated by Jeremy Jeremy 1 week, 3 days ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #4137
    Avatar
    leaena
    Participant

    Hi Jeremy,

    I’m not sure if this is a bug report or a question or both!

    Tl;Dr: I want to update a variable based on the value of another variable and I don’t know how.

    Context:
    I’m currently trying to update a reaction time variable (as I am still having trouble with the EventTime timestamps, I have been preferring to calculate everything by hand during the experiment). Maybe this isn’t your preferred method, I’m sorry. Anyway, I have a variable called ratingRT which (in the original version) gets set ( v => Date.now() ) as soon as the sentence is displayed, and then updates ( v => Date.now() – v ) when the rating is selected on a scale. Either this update happens after scale.wait() or in scale.settings.callback(), I have tried both. However this results in a…bug? error? me doing something wrong? where the reaction time just ends up as Date.now() when the replay button is pressed, because when the replay button is pressed it gets started counting over again when the sentence is displayed. I’ve tried to get around this issue by just updating a variable called sentenceDisplayTime each time a sentence is displayed, and instead of
    getVar(“ratingRT”).set( v => Date.now() – v )
    I am using:
    getVar(“ratingRT”).set( v => Date.now() – getVar(“sentenceDisplayTime”)

    This results in ratingRT coming out as the value “None”. This despite the fact that both ratingRT and sentenceDisplayTime are set to 0 when they are initialized. What’s going on?

    Thanks for any help!
    Best,
    Leo

    #4138
    Jeremy
    Jeremy
    Keymaster

    Hi Leo,

    It’s hard to tell without seeing your code, but I suspect that the replay makes it so that ultimately, in the sequential flow of commands in your experiment, the command .set( v => Date.now() ) gets executed more than once, and the last time it is executed happens after the last time .set( v => v - Date.now() ) is executed.

    Are you trying to record the RT both for the first pass and for the replay? Or only for the replay? In any case, it would probably be cleanest to just use different variables on the two different occasions, e.g. (adapting the code from this topic):

    newText("contextText", "Look at the square below").print(),
    newCanvas("square", 200,200).settings.css("background","red").print(),
    // Var element for the first RT
    newVar("RTfirst", 0).settings.log().set(v => Date.now()),
    newButton("ok", "OK").print().wait().remove(),
    newText("instructions", "How red is it?").print(),
    newScale("firstScale", 7).settings.log().print().wait(),
    getVar("RTfirst").set(v => Date.now() - v),
    newButton("Replay").print().wait().remove(),
    // Removing everything still on screen
    getText("contextText").remove(),
    getCanvas("square").remove(),
    getText("instructions").remove(),
    getScale("firstScale").remove(),
    // Wait 500ms before reprinting
    newTimer(500).start().wait(),
    getText("contextText").print(),
    // Var element for the second RT
    newVar("RTsecond", 0).settings.log().set(v => Date.now()),
    getCanvas("square").print(),
    getButton("ok").print().wait().remove(),
    getText("instructions").print(),
    // Print a new scale
    newScale("secondScale", 7).settings.log().print().wait(),
    getVar("RTsecond").set(v => Date.now() - v)

    Unfortunately you cannot use getVar after => in the set command the way you’ve tried, because it actually is in a non-PennController environment (which incidentally also makes it possible to use Date.now() upon runtime). If you really need to access the value of the Var element there, you need to use getVar("sentenceDisplayTime")._element.value.

    Let me know if you have more questions!

    Jeremy

    #4149
    Avatar
    leaena
    Participant

    Hi Jeremy,

    Just FYI, using getVar("sentenceDisplayTime")._element.value also doesn’t work to give us the actual value (it shows up as the EventTime timestamp again, so that .set call just doesn’t do anything it seems?). We settled on ignoring it since it’s not a very reliable measure anyway given the existence of a replay button…

    Thanks!
    Leo

    #4150
    Jeremy
    Jeremy
    Keymaster

    Hi Leo,

    Thank you for letting me know. I don’t know what is happening exactly in your case, but maybe a comparison with a functional example would help identify the source of the problem:

    PennController(
        newText("sentence").print()
        ,
        newVar("sentenceDisplayTime").set(v=>Date.now())
        ,
        newScale(10).print().wait()
        ,
        newVar("ratingRT").set( v => Date.now() - getVar("sentenceDisplayTime")._element.value )
        ,
        newText("")
            .settings.text( getVar("ratingRT") ) 
            .print()
        ,
        newButton("Push").print().wait()
    )

    Will display how long it took to select an value on the scale.

    Jeremy

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.