| Reference | Downloads | Github

Manikin approach avoidance task

Hello everyone,

I’m new to PsychoPy (version 1.90.1, Builder view, Windows10) and Python and have trouble creating an experiment where I’d like to simultaneously present two components at first (a randomly selected text component and an image component) and then replace the image component with another image while keeping the text component presented until the routine is over. I’d greatly appreciate any support :slight_smile:

In my experiment, I’d like participants to move a manikin on the screen toward (approach) or away from (avoidance) a randomly selected name from a list by pressing either the right or the left key (originally, I thought of using a joystick, but apparently, there might be some problems with that: ?). So the manikin should be centered at the beginning of each trial and then ‘move’ to the right or to the left according to participants’ keypress.

I’ve created bmp images of manikins in three different positions (centered = ManM, left = ManL, and right = ManR) to simulate manikin movement and an xlsx file containing the names in one column (header: ‘name’). In each trial, one of these names is presented with the names component.
I’ve also added two code components - one that randomly makes the names appear left or right (code):

Begin Routine:

if random()>0.5:
    targetPos=[-0.5, 0.0]#on the left
    targetPos=[+0.5, 0.0]#on the right

and one that enables respective presentation of either ManL or ManR according to participants’ key press (code_2):

Begin Routine:

ManL.tStart = 0
ManR.tStart = 0

Each Frame:

if response.keys == 'left':

elif response.keys == 'right':

So far, everything looks as expected except for the names which disappear after pressing one of the predefined keys (so one of the names is presented together with ManM, but as soon as either ManL or ManR appears, the name disappears).
I’ve tried to change the settings of ‘names’:

stop → condition → $ManL.status==FINISHED or ManR.status==FINISHED

but then the names didn’t show up at all.
Do you know what I could do to keep the names presented together with ManL/ ManR until the end of each trial1 routine?

I would be very grateful for any support - thank you so much!

ManM + one of the names:

ManL - name is missing:

namegame.psyexp (18.6 KB)

The odd behaviour you are seeing is because of using win.flip() and core.wait(). These functions are fine to use when writing your own experimental code from scratch but they should never be used within Builder. Builder-generated code itself is structured inherently around a drawing loop, calling one win.flip() for every screen refresh (typically 60 times a second). This is good, as you don’t need to worry about doing that stuff yourself. But by you sending your own win.flip() and then pausing everything for 1 s, you’ve stopped Builder’s own code from being able to update stimuli, listen for keypresses and so on: you’ve basically frozen the experiment. So you need to delete any lines that use those functions.

I would suggest that you can simplify things immensely by just having one manikin figure image, and update its position, rather than maintain three separate images. Then you don’t need to worry about switching images on and off: the same image is always visible, you just shift it as required. e.g. something like:

if response.keys[0] == 'left':
    manikin.pos = [-0.25, 0]
elif response.keys[0] == 'right':
    manikin.pos = [0.25, 0]

Builder will take care of re-drawing it automatically, as it will for your text stimuli, which stay in place.

1 Like

Hi Michael,

thank you very much for your reply, I truly appreciate your support!

I replaced code_2 with your suggested code (instead of ‘manikin.pos’ I wrote ‘ManM.pos’) and deleted ManL and ManR. When I inserted the code into the code_2-parameters ‘Begin Routine’ and ‘Each Frame’, I received an error message:

After that, I tried to insert it into the ‘End Routine’ field, but then the position of the manikin didn’t change after keypress.

When I removed ‘[0]’ from code_2 and instead used

if response.keys == 'left':
    manM.pos = [-0.25, 0] 
elif response.keys == 'right':
    manM.pos = [0.25, 0] 

the manikin would either stay centered after pressing a key if it was inserted into the ‘Begin Routine’ field, or – if I put the code into ‘Each Frame’ or ‘End Routine’ – the presented name didn’t stay and was replaced by another name after every keypress. Additionally, I needed to press one of the keys to center the manikin again, which I would like to happen automatically after 1 second.

I then tried creating a second image component of the centered manikin (manikinM) while adjusting the code to it. This also lead to a static manikin. I suspect this might have something to do with the position settings of manikinM which initially where set on (0, 0) – I thus tried changing the code to

if response.keys == 'left':
    manPos = [-0.25, 0] 
elif response.keys == 'right':
    manPos = [0.25, 0] 

and entering ‘$manPos’ into the position settings of manikinM

but this produced an error:


NameError: name ‘manPos’ is not defined.

Do you have any further recommendations on how I could solve this problem?

Many thanks again!