Cannot getVal correctly

PennController for IBEX Forums Support Cannot getVal correctly

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #6683
    Rick
    Participant

    Hi Jeremy,

    I have one problem with referring to the already-created global variable. The mini code is as follows:

    Sequence ("createID","experiment","bye")
    
    newTrial("createID",
      newVar("subjID")
          .global()
          .set(String.fromCharCode(65+Math.floor(Math.random() * 26)) + Math.floor((Math.random() * 10000) + 1))
           .log()
        )
        .log("ParticipantID",getVar("subjID"))

    ….Experiment trials(skipped).log("ParticipantID",getVar("subjID"))

    newTrial("bye",
      
        newText("<p>Thank you for doing this study!!!</p>")
    		.settings.center()
            .print()
        ,
        newText("Your participant id number is:").settings.center()
            .print()
        ,
        newText()
            .text(getVar("subjID"))
    		.settings.center()
            .print()
        ,
        newButton("void")
            .wait()
        )
        .setOption("countsForProgressBar" , false)
        ;

    The errors are as follows
    [22:24:34] Command ‘0’ unknown on Var element ‘subjID’. (PennController: 36)
    [22:24:34] Command ‘length’ unknown on Var element ‘subjID’. (PennController: 36)
    [22:24:34] Command ‘parentNode’ unknown on Var element ‘subjID’. (PennController: 36)

    I tried many times(always get the errors), and part of the code ( newText()
    .text(getVar(“subjID”))) in “bye” could not get the value of “subjID” variable, while the experiment trials could append the “subjID” as a column “ParticipantID” successfully. It is really confusing: if it is not global, it could not have been appended to the experiment trials ;if it is global, the “bye” session could not refer to it and get the value successfully. Could you offer me some suggestions?

    Thanks!

    • This topic was modified 3 years, 1 month ago by Rick.
    • This topic was modified 3 years, 1 month ago by Rick.
    • This topic was modified 3 years, 1 month ago by Rick.
    • This topic was modified 3 years, 1 month ago by Rick.
    • This topic was modified 3 years, 1 month ago by Rick.
    • This topic was modified 3 years, 1 month ago by Rick.
    #6690
    Jeremy
    Keymaster

    Hi Rick,

    As far as I can tell, you don’t need a Var element to do what you’re after:

    subjID = String.fromCharCode(65+Math.floor(Math.random() * 26)) + Math.floor((Math.random() * 10000) + 1)
    
    Sequence ("experiment","bye")
    
    Header(
      // ...
    )
    .log("ParticipantID", subjID)
    
    // ... experiment
    
    newTrial("bye",
        defaultText
            .center()
            .print()
        ,
        newText("<p>Thank you for doing this study!!!</p>")
        ,
        newText("Your participant id number is:")
        ,
        newText(subjID)
        ,
        newButton("void")
            .wait()
    )
    .setOption("countsForProgressBar" , false)

    What you report is a known bug, I’ll work on fixing it for the next release (or the one after that)

    Jeremy

    #6691
    Rick
    Participant

    Hi Jeremy,

    Thanks so much for your quick reply! Your solution works perfectly!

    It’s great to know that it is a bug and also I learned a lot from your code (that I could define the variable not simply in newVal()).

    Best,
    Rick

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