Implicit motivation measure using Psychopy

Hi all,

I try to construct an implicit motivation measure in Psychopy. Participants will see different images. In order to continue viewing the image, my participants will need to show some effort and press the space key repeatedly. I mean, the opacity of the image should decrease if participant is not pressing the key and the image should disappear completely, the next trial should begin. But if participant presses the key, the image should be displayed with maximum opacity for as long as she presses the key. Do you have any ideas what kind of a code component I can use for this task?

Begin Routine

reset =0

Each Frame

keys = event.getKeys()
if ‘space’ in keys:
     reset=t
elif t>= reset+4:
     continueRoutine =False 
else:
     image.setOpacity((4+reset-t)/4)
1 Like

Thank you very much for such a fast reply!
The automatic translation in JS is not working, I’m afraid - is there any way to translate that code in JS properly?

What do you mean by not working?

Please could you show a screenshot of your code component?

BTW, please see my crib sheet for how to define event in code_JS

My bad, this one worked, thank you very much for your help!

The experiment works just fine thanks to you, but it is not recording the number of clicks - is there a way to record how many times they pressed the spacebar?

Begin Routine
nClicks=0

Each Frame next to reset=t
nClicks+=1

End Routine
thisExp.addData(‘nClicks’,nClicks)
thisExp.addData(‘timeout’,t)

1 Like

Great, thanks a lot, that solved the problem!

I used PsychoPy Python to Javascript crib sheet - Google Docs
to translate some pieces of this code in JS

1 Like