GetVar Error

PennController for IBEX Forums Support GetVar Error

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #10777
    lh555
    Participant

    Hi Jeremy,

    I’ve been trying to write code for an experiment that at one point prints out the value of a Var element. However, I can’t get it to work and get an error.
    For reference, this is the code:

    
    PennController.ResetPrefix(null);
    newTrial('test',
        newVar('var-int','hello')
        ,
        newText('text',getVar('var-int'))
            .print()
        ,
        newButton('button','Click')
            .print()
            .wait()
    )
    

    I get the following error: ‘Command ‘replace’ unknown on Var element ‘hello’’
    Any help would be greatly appreciated.

    #10787
    Jeremy
    Keymaster

    Hi,

    You cannot reference a Var element in a newX command, because elements are created upon opening the experiment but evaluated upon runtime

    The solution is to use the .text command:

    newTrial('test',
        newVar('var-int','hello')
        ,
        newText('text')
            .text( getVar('var-int') ) 
            .print()
        ,
        newButton('button','Click')
            .print()
            .wait()
    )

    Jeremy

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