Description of the problem: I’m new to PsychoPy and Pavlovia. I have 2 images shown on a display. Now I want the participants to move the objects with the arrow keys on the keyboard.
In Python I created 2 objects and specified the position with (C, -0.3) or (E, -0,3). In the custom code I wrote in the Begin Experiment tab
kb = keyboard.Keyboard()
kb.getKeys(‘right’, ‘left’, ‘backspace’)
C=0.025
E=-0.025
and in the Each Frame tab:
if event.getKeys(‘left’):
E-=0.01
if event.getKeys(‘right’):
E+=0.01
This works perfectly and I can move the one object to the left or the right.
But when I upload it to Pavlovia it doesn’t work. How can I translate this code to Javascript so that it also works on Pavlovia?
You need two code components. code_JS set to JS and then your normal one set to Auto. My previous message contained Python script that I know the auto translate will translate correctly.
Moved the sound code to code_JS and removed the event definition from the Python code.
Added an ISI in the outer loop
Space now ends the inner loop instead of ending a trial that only lasts one frame anyway. To do this I switched the names of the loops so the inner loop is called trials.
Removed all setPos and changed Polygons 3 and 4 to update every routine since each trial only lasts 1 frame anyway
Stopped the polygons swapping over
Save the values of C and E each frame.
Stopped space ending the loop if trials.thisN < 26
I’ve only tested it offline. I’ll send you back the file so you can see if it’s working better now.