| Reference | Downloads | Github

Input text continues from routines in loop

I’m running Psychopy3. I have an experiment in which participants view trivia questions and then give three separate responses to a question that appears on the screen. So, I have a loop that contains three routines and inputs questions from the same excel file. In the first routine the participant types in a reponse and presses enter. In the second routine they press a number key and same with the third. When I run the experiment on my computer there is no carryover, but when I run it on Pavlovia the number from the third routine carry’s over to where the participant has to type in a response when the loop starts the next iteration. I think the issue lies in the JS code. Below its my py code and then my js. I’ve also used this same code on a different experiment and not had this issue on Pavlovia.

#Begin Routine
modify = False
Text.text = ‘’

#Each Frame
keys = event.getKeys()
if len(keys):
if ‘space’ in keys:
text_69.text = text_69.text + ’ ’
elif ‘backspace’ in keys:
text_69.text = text_69.text[:-1]
elif ‘lshift’ in keys or ‘rshift’ in keys:
modify = True
elif ‘return’ in keys:
continueRoutine = False
if modify:
text_69.text = text_69.text + keys[0].upper()
modify = False
text_69.text = text_69.text + keys[0]

#end Routine
thisExp.addData(“typedWord”, text_69.text)

#JS Code

#begin routine
modify = false;

text_69.text = ‘’;

#Each frame
let theseKeys = psychoJS.eventManager.getKeys();
if (theseKeys.length > 0) { // at least one key was pressed
textAdd = theseKeys[theseKeys.length-1];

if (textAdd === ‘return’) {
textAdd = ‘’; // Add nothing
continueRoutine = false; // End routine (if that is what you want)
} else if (textAdd === ‘space’) {
textAdd = ’ '; // Add a space
} else if (textAdd === ‘backspace’) {
text_69.text = text_69.text.slice(0, -1);
textAdd = undefined;
} else if ([‘lshift’, ‘rshift’].includes(textAdd)) {
modify = true;
} else if (textAdd !== undefined) {
if (modify) {
text_69.text = text_69.text + textAdd.toUpperCase();
modify = false;
} else {
text_69.text = text_69.text + textAdd
textAdd = undefined;

#end routine
psychoJS.experiment.addData(“typedWord”, text_69.text)
text_69.setText(’’) // empty the onscreen text ready for next input ```

I do have the settings on discard previous.
Any help would be greatly appreciated!

P.s. I'm not sure how to format my script so if someone could help me I'll edit my post.

You aren’t clearing the keyboard in JS

You need to define event as per my crib sheet and then auto translate event.clearEvents()

Is there a place where I can find your crib sheet? Sorry I’m a novice coder at best.

Nevermind! I found your crib sheet in your profile. Thank you so much that worked!

1 Like