Reply To: Cannot reset value of newVar

PennController for IBEX Forums Support Cannot reset value of newVar Reply To: Cannot reset value of newVar

#6877
Jeremy
Keymaster

Hi,

I am not sure where you saw such a use of getVar(...).value, but it’s a method you use to inject native JavaScript in your code. In your case, you’re accessing the value of the Var element before the trial has even started. This guide should bring insights into this issue.

The proper PennController way of accomplishing what you’re trying to do is:

newTrial(
    // Initialize variable
    newVar("audFile","None").set( "variable is changed" ),
    newText( "This now says 'variable is changed':" )
        .after( newText().text(getVar("audFile")) )
        .print()
    ,
    newTimer(3000).start().wait(),
    clear()
    ,
    // Print letter to be typed
    newText("letter", "Now please press A")
        .css("font-size", "24pt")
        .log()
        .print()
    ,
    // Get keypress
    newKey("keypress", "as")
        .log()
        .wait()
        .test.pressed( "A" )
        .success( 
            getVar("audFile").set("correct"),
            newText( "Correct!" ).print(),
            newTimer(1000).start().wait()
        )
        .failure(
            getVar("audFile").set("wrong"),
            newText( "Wrong!" ).print(),
            newTimer(1000).start().wait()
        )
    ,
    // Print the final value of the variable
    newText( "This should say either 'Correct!' or 'Wrong!' and it does:")
        .after( newText().text(getVar("audFile")) )
        .print()
    ,
    newTimer(1000).start().wait()
)

If your Var element is trial-wise, which I take to mean local (ie. non-global) then you don’t need to use the global command

Jeremy