psychopy.org | Reference | Downloads | Github

Problem in if condition

What are you trying to achieve?:

My expriment design:

  1. 2 pictures show on the screen for 2 sec
  2. The screen is empty and the subject need to choose by using key press which picture he want to see again
  3. While the subject press the space key the picture will be present until he stop pressing

What did you try to make it work?:
I did the first step (1), but I couldnt succes to do the rest.

What specifically went wrong when you tried that?:
I dont know how to write the if condition and the multy pressing on the space key.

Thank you

This is the code that I used but I don’t think it right:

if key_resp == 'rigth':
    image3 = $Image1
    else:
        image3 = $image2

should I import the excel that I used to show the picture with, also to my code?
Thanks

Try

if key_resp.keys == 'right':
    image3 = image1
else:
    image3 = image2

Hi
I tried this but it’s still writing that I have a Syntax Error

I’ve just edited the indentation in my post

I change the indentation and now it’s writing:
if image3.status == NOT_STARTED and 0.0:
AttributeError: ‘str’ object has no attribute ‘status’

Is image3 a filename or am image component? Based on your code I assumed the former but the error message suggests the latter.

It’s an image component

Then image3.image should be used instead

Now the experiment is runing but it’s not showing image3
What should I write here?

If you put $thisImage in the Image field then you could change the code to

if key_resp.keys == 'right':
    thisImage = image1
else:
    thisImage = image2

If image1 and image2 are filenames not variables then it should be something like

if key_resp.keys == 'right':
    thisImage = "image1.jpg"
else:
    thisImage = "image2.jpg"