PennController for IBEX › Forums › Support › Cannot getVal correctly
Tagged: global variable
- This topic has 2 replies, 2 voices, and was last updated 3 years, 6 months ago by Rick.
-
AuthorPosts
-
March 2, 2021 at 11:41 pm #6683RickParticipant
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, 6 months ago by Rick.
- This topic was modified 3 years, 6 months ago by Rick.
- This topic was modified 3 years, 6 months ago by Rick.
- This topic was modified 3 years, 6 months ago by Rick.
- This topic was modified 3 years, 6 months ago by Rick.
- This topic was modified 3 years, 6 months ago by Rick.
March 3, 2021 at 12:21 pm #6690JeremyKeymasterHi 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
March 3, 2021 at 1:08 pm #6691RickParticipantHi 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 -
AuthorPosts
- You must be logged in to reply to this topic.