psychopy.org | Reference | Downloads | Github

Cannot use variable in "Conditions" field of loop for online experiments?

Hi there!

To use specific lists for each participant I use some code in the Conditions field of a loop in the local version of my experiment: “Lists\list” + $subject + “.csv” with subject beeing earlier defined as subject = str(expInfo[“participant”]) in a code snippet at the beginning of the experiment. This technique, however, does not seem to be translated to the html version of the experiment. Is there an alternative way of giving each participant a different Conditions file?

Thanks for the support!

  • \ is a Windows-only path separator. You shouldn’t use it for code that will run on another operating system (like the Linux server that will run your experiment online). There are more sophisticated approaches, but the easiest thing to do is just use / instead (including when running on Windows).
  • don’t use $ in the middle of an expression - this isn’t valid syntax for Python or Javascript. When necessary, it should only appear at the very start of an expression, as a hint to Builder that this expression should be treated as code, rather than a literal value.
  • When experiments run online, they consist of Javascript rather than Python. So you need to provide a Javascript alternative for any of your custom code. In your code component, select “Both” for the code type, and then you’ll get a second pane where you can translate the Python expression into the Javascript equivalent.

Having said that, I don’t know enough to translate that simple snippet str(expInfo[“participant”]) – hopefully someone else can chime in here.

Thanks for the quick reply! It helped my basic understanding a lot.

I got it to work using A = 'Lists/list'.concat(expInfo['participant'],'.csv')
as a code snippet in the beginning of the experiment and then using $A in the Conditions field of the loop.