| Reference | Downloads | Github

Set conditions for Pavlovia

I have built a version of Stroop that uses images. The Conditions field in trial Properties sets the image to show on each trial as follows:


It selects one of two stimulus files based on the odd/even participant number. This works fine within PsychoPy but does not run in Pavlovia. It doesn’t like the “str” here. Do I need to translate this line into JS, inside the Conditions field?

@georgewm, str is a Python built-in function. In JavaScript, you can concatenate strings and ints without explicit conversion, and even perform the modulo on a string, so long as it looks like a number - JS performs the conversions for you. E.g.,

$'stimTypes' + 1 + expInfo[‘participant’] % 2 + '.xlsx'

Thanks for this translation. I just tried to replace the content of the Conditions field with this, but the Builder user interface would not let me confirm the change, perhaps because it is not legal Python.

Maybe I need to manually add the code somehow after the program has been converted to JavaScript?

Ah yes, it is causing an error when PsychoPy looks for the file. Try this instead. Add a code component, and in the Begin Experiment tab, use:


condFile = 'stimTypes' +'1'+ expInfo['participant'] % 2 + '.xlsx'

JavaScript - from the new auto-translate function in code component

condFile = ((("stimTypes" + "1") + (expInfo["participant"] % 2)) + ".xlsx");

Now, set your conditions file to $condFile, and export the HTML.

Thanks, this was the solution, though in case anyone reading this is planning to implement the same, I had to edit the code lines as follows to make it work:
condFile =“stimTypes”+str(1+int(expInfo[‘participant’])%2)+".xlsx"
condFile = (((“stimTypes”) + (1+(expInfo[“participant”] % 2))) + “.xlsx”);

On to the next wrinkle…
The images listed in the .xlsx file are in the same folder as the .xlsx file itself, and this works fine in PsychoPy, but the JS version can’t find them. I’m guessing that they need to be in the HTML folder for online use, so have to figure out how to move them all, presumably within Github somehow.

1 Like

If PsychoPy cannot find the image files, then you need to manually copy them to the html > resources folder, and sync them with Pavlovia.