Simon experiment

Hello,
I have been trying to design a simple simon task in psychopy. I took help from an online youtube video.
The link is:

Instead of using X and O, in my experiment I am trying to use red and blue square images. So, I made some changes in the code they wrote. I replaced X and O with red and blue square images. Probably I did some mistake in the syntax, that’s why there is an error showing that the for eg., blue_square.png is not defined.

Could you please check and point out the mistake and tell me the correct way to write it.
Here is the code.

if expInfo['counterbalance'] == '0':
    bindings = {'blue_square.png': 'm', 'red_square.png': 'z'}
    if thisTrial['condition'] == 'incongruent':
        if thisTrial['stim'] == 'blue_square.png':
            thisTrial['stim'] = thisTrial['stim']
            'red_square.png' = ''
            ans = 'm'
        elif thisTrial['stim'] == 'red_square.png':
            'blue_square.png'= ''
            'red_square.png' = thisTrial['stim']
            ans = 'z'
    elif thisTrial['condition'] == 'congruent':
        if thisTrial['stim'] == 'blue_square.png':
            'blue_square.png'= ''
            'red_square.png'= thisTrial['stim']
            ans = 'm'
        elif thisTrial['stim'] == 'red_square.png':
            'blue_square.png'= thisTrial['stim']
            'red_square.png' = ''
            ans = 'z'
elif expInfo['counterbalance'] == '1':
    bindings = {'red_square.png': 'm', 'blue_square.png': 'z'}
    if thisTrial['condition'] == 'incongruent':
        if thisTrial['stim'] == 'blue_square.png':
            'blue_square.png' = '' 
            'red_square.png' = thisTrial['stim']
            ans = 'z'
        elif thisTrial['stim'] == 'red_square.png':
            'blue_square.png' = thisTrial['stim']
            'red_square.png' = ''
            ans = 'm'
    elif thisTrial['condition'] == 'congruent':
        if thisTrial['stim'] == 'blue_square.png':
            'blue_square.png' = thisTrial['stim']
            'red_square.png' = ''
            ans = 'z'
        elif thisTrial['stim'] == 'red_square.png':
            'blue_square.png' = '' 
            'red_square.png' = thisTrial['stim']
            ans = 'm'

I hope you can help me.
Thank you

This doesn’t make sense to me since neither is a variable.

I’m going to guess that you have a stimulus component called red_square and that you are trying to update its image attribute. The way to do that is to use the correct attribute name, which is .image, and not to put that in quotes. e.g.

red_square.image = thisTrial['stim']

The docs for that attribute are below. You need to refer to the documentation rather than just guess at attribute names:

Hi I have copied the code from this youtube video and designed this experiment but when I run i get this in runner:
C:/Users/User/Downloads/Simon_task.xlsx as conditions, 4 conditions, 2 params
C:\Program Files\PsychoPy\lib\site-packages\scipy_init_.py:146: UserWarning: A NumPy version >=1.16.5 and <1.23.0 is required for this version of SciPy (detected version 1.24.4
using PyQt5
pygame 2.1.0 (SDL 2.0.16, Python 3.8.10)
warnings.warn(f"A NumPy version >={np_minversion} and <{np_maxversion}"
WARNING: pytables package not found. ioHub functionality will be disabled.
Hello from the pygame community. Contribute - pygame wiki
WARNING: pytables package not found. ioHub functionality will be disabled.
Traceback (most recent call last):
14.3053 WARNING User requested fullscreen with size [1536 864], but screen is actually [1920, 1080]. Using actual size
C:\Program Files\PsychoPy\lib\site-packages\scipy_init_.py:146: UserWarning: A NumPy version >=1.16.5 and <1.23.0 is required for this version of SciPy (detected version 1.24.4
File “C:\Users\User\Downloads\simon\simon-r\Simon Test Experiment_lastrun.py”, line 840, in
run(
File “C:\Users\User\Downloads\simon\simon-r\Simon Test Experiment_lastrun.py”, line 319, in run
if expInfo[‘counterbalance’] == ‘0’:
KeyError: ‘counterbalance’
################# Experiment ended with exit code 1 [pid:2008] #################
3204.1669 EXP Imported C:/Users/User/Downloads/Simon_task.xlsx as conditions, 4 conditions, 2 params
3204.1717 INFO Loaded monitor calibration from [‘2023_08_28 14:03’]

what could be the possible reason? And how can I correct this?

Thanks in advance.

Regards

This error suggests that you don’t have counterbalance in the expInfo dialogue box.