| Reference | Downloads | Github

Counterbalancing image syntax error

OS (e.g. Win10): MacOS Catalina 10.15.3
PsychoPy version (e.g. 1.84.x): 3

I am trying to update a task that was originally built in PsychoPy2 to work in PsychoPy3 and eventually Pavlovia. I’m new to working with PsychoPy and Python, so this may have an easy fix that I’m not seeing. I need help with a code component that displays the error: “/* Syntax Error: Fix Python code */” on the JS side of the code. I have seen that this error is often caused by using syntax that no longer works in a new version of PsychoPy.

The code that causes this error is:

stims = {
    'go': {
        'win': 'P%s.png' % MGMorder[0],
        'lose': 'P%s.png' % MGMorder[1]
    'nogo': {
        'win': 'P%s.png' % MGMorder[2],
        'lose': 'P%s.png' % MGMorder[3]

Info about what we are trying to do: The task is an updated go-no go paradigm with four conditions: go-win, go-lose, nogo-win, nogo-lose. We have four image stimuli (names: P1.png, P2.png, P3.png, P4.png). We want the images to be counterbalanced so that the images are associated with different conditions across participants (i.e. each participant only sees one counterbalancing order for the entirety of the task, but different participants see different orders). Right now, the experimenter enters in the numbers 1, 2, 3, 4 in a specific order in an “MGMorder” box in the experiment info at the beginning of the experiment. These numbers inform the code above on which image should be tied to which condition.

Any help would be appreciated! If you think the code above could work with small syntax adjustments, that would be great, but also open to totally changing the way we code this.

This method of string formatting doesn’t work online. You would need to use

'win': 'P'+str(MGMorder[0])+'.png'

If you aren’t intending to use the experiment online then you can ignore this syntax error.