psychopy.org | Reference | Downloads | Github

Problem with seeing typed words in pavlovia

Hey,

I posted earlier but I will provide more detail here. I am having participants type in some words they see. I want them to see what they have typed. It works fine when I run it on builder. The problem comes when I want to run it with pavlovia:
image
The code I have is the following:

Begin experiment:

PY:
msg=’ ’
numkeys=0

Java:
msg = " ";
numkeys = 0;

EACH FRAME:
PY:
templist=key_resp_12.keys
if templist.count(‘return’)==1:
key_resp_12.keys.pop()
key_resp_12.keys=’’.join(key_resp_12.keys)
key_resp_12.rt=key_resp_12.rt[0]
continueRoutine=False
elif templist.count(‘space’)==1:
key_resp_12.keys.pop()
elif templist.count(‘lshift’)==1:
key_resp_12.keys.pop()
elif templist.count(‘backspace’)>=1 and len(key_resp_12.keys)>=2:
key_resp.keys_12.remove(‘backspace’)
key_resp_12.keys.pop()
msg=msg[:-1]
elif templist.count(‘backspace’)>=1 and len(key_resp_12.keys)==1:
key_resp_12.keys.pop()
elif (len(key_resp_12.keys)-1) == numkeys:
msg=’’
msg=msg.join(key_resp_12.keys)
numkeys=len(key_resp_12.keys)

JAVA:
templist = key_resp_12.keys;
if ((templist.count(“return”) === 1)) {
key_resp_12.keys.pop();
key_resp_12.keys = “”.join(key_resp_12.keys);
key_resp_12.rt = key_resp_12.rt[0];
continueRoutine = false;
} else {
if ((templist.count(“space”) === 1)) {
key_resp_12.keys.pop();
} else {
if ((templist.count(“lshift”) === 1)) {
key_resp_12.keys.pop();
} else {
if (((templist.count(“backspace”) >= 1) && (key_resp_12.keys.length >= 2))) {
key_resp.keys_12.remove(“backspace”);
key_resp_12.keys.pop();
msg = msg.slice(0, (- 1));
} else {
if (((templist.count(“backspace”) >= 1) && (key_resp_12.keys.length === 1))) {
key_resp_12.keys.pop();
} else {
if (((key_resp_12.keys.length - 1) === numkeys)) {
msg = “”;
msg = msg.join(key_resp_12.keys);
}
}
}
}
}
}
numkeys = key_resp_12.keys.length;

In addition, I have this so that it shows it on the screen:
image
Does anyone know why I am only getting the problem when running it online?

An extra reason for why it won’t work (apart from .join not working the same way in Python and JavaScript) is because you can’t put Python code into Builder components. The Auto translate (and the possibility of manual editing) only works in code components.

But it works when I run it on builder. It was the only way I found to make it display the typed text on the screen.

Builder uses Python locally.
Python doesn’t work online
PsychoPy uses JavaScript online.
The languages are different so you can’t expect code that works locally to work online unchanged.

Have a look at https://pavlovia.org/Wake/brookes-template-2020 to see how I have a two digit age typed response online.

Ok, thanks! So I have looked at your experiment and adapted your age bit to mine. It seems to work again in the builder, but it is giving me a different error when I run it online

  • TypeError: undefined is not an object (evaluating ‘event.clearEvents’)

You need event=psychoJS.eventManager; in code_JS for that to work

Could tell me how to add it?

Please could you look at my crib sheet and let me know if my instructions aren’t clear enough

Hey, thanks for your help. They are clear. I added this to the code_JS:
cursorCounter = 0;
cursorVariable = “|”;
captured_string = “”;
subject_response_finished = false;
event=psychoJS.eventManager;

but I still get the same problem. Do you know why?

Please could you show screenshots of the two relevant code components? Alternatively, if you make the experiment public or share it with me I can take a look.

Hey Wakecarter,

I think I made it work. I owe you a big ONE! truly thankful. I hope you don’t mind if I ask something else… it only allows me to type in 2 characters, do you know how I should do it to type in more characters?

Ok, so I think I managed to do this! THANK you.

Cool. I don’t have easy access to my code on my phone but I know I specifically limit age responses to two digits (or 0 for prefer not to say)