Coding error from Windows to Mac

The code was copied and pasted from the Windows PsychoPy to Mac’s PsychoPy, and the code does not work. The code is:

for stimulus in [image, image_4,image_5]:

if mouse_click.isPressedIn(stimulus):

    # Yes, so store the reaction time in the data:
    thisExp.addData('RT', t)

    if stimulus.image == eval(img_corr):

        thisExp.addData('img_score', 1)

    elif stimulus.image==eval(emp_corr):
        thisExp.addData('emp_score', 1)
    else:
        thisExp.addData('que_score',1)

    if stimulus.image == eval(CorrAns):
        thisExp.addData('score', 1)

    else:
        thisExp.addData('score', 0)

    continueRoutine = False 

When I run the experiment, there is an error:

Running: /Users/tantingtang/Desktop/Grace/sen_pic_matching_lastrun.py

File “/Users/tantingtang/Desktop/Grace/sen_pic_matching_lastrun.py”, line 518
for stimulus in [image, image_4,image_5]:
^
IndentationError: expected an indented block

I am new to this program. Would you please help me? Thank you!!

@Tan_Ting_Tang, you have an indentation error in your code not actually related to the Windows or Mac OS. See Here to learn about how Python uses indentation to structure code.
To fix:

for stimulus in [image, image_4,image_5]:

    if mouse_click.isPressedIn(stimulus):

        # Yes, so store the reaction time in the data:
        thisExp.addData('RT', t)
1 Like

@dvbridges hank you for you reply, but when I replaced the original code with yours, there is still the same error notification shown on the screen.

Yes this means your for loop is not indented correctly in the context of the preceding code. If you are still having problems after reading the link, please post your code.

Thank you for your prompt reply.
The code is

for stimulus in [image, image_4,image_5]:

if mouse_click.isPressedIn(stimulus):
    # Yes, so store the reaction time in the data:
    thisExp.addData('RT', t)

if stimulus.image == eval(img_corr):

    thisExp.addData('img_score', 1)

elif stimulus.image==eval(emp_corr):

    thisExp.addData('emp_score', 1)

else:

    thisExp.addData('que_score',1)

if stimulus.image == eval(CorrAns):

    thisExp.addData('score', 1)

else:

    thisExp.addData('score', 0)

continueRoutine = False

(I don’t know why the for statement is not indented properly.)
Thank you for your help!

Thanks @Tan_Ting_Tang, is that all of your code? If you upload the file that might help.

sen_pic_matching.psyexp (35.8 KB)

This is the file. Thank you so much ! @dvbridges

Thanks @Tan_Ting_Tang, could you please compile the script for this experiment that gives you the error, and post the code as a file? That way, I can see what code you are seeing.

Thank you @dvbridges. I wish I could upload the file, but it seemed that the file format is not accepted here. I have provided the screenshots. I hope those pictures would be helpful. Sorry if I have misinterpreted your request.

Hi @Tan_Ting_Tang, I think you have this error because you are using an experiment file created in later version of psychopy that uses a mouse component not entirely compatible with the version of psychopy on the Mac. You can solve this problem by opening your experiment on the Mac, and deleting your mouse component and creating another identical one, also called “mouse_click”. This new mouse component will then be compatible with the version of psychopy on the Mac, and your error should disappear. I have attached a new version of your experiment to demonstrate the fix:

sen_pic_matching_newmouse.psyexp (35.7 KB)

1 Like

@dvbridges
OMG !!! It works now!!!
It is very motivating !!!
Thank you for your patience and help!!!