Free typing Py --> JS

Hello everyone,
I am having a problem with some free typing code for an online experiment. The python code works fine (I’m using a builder keyboard object to listen to the keys). The participant can type a response and it will display in its entirety on the screen.

I have already made some adjustments such as the .getKeys() call in the first line and the .join() call in the last line.
However, online, only one letter shows up at a time, lasting for about a frame before disappearing.

Does anyone know what I can do to make the behavior the same?

I don’t use join or pop for this.

Thanks @wakecarter, I’ll play around with this code.
From what I’ve seen, using core.quit() causes an error in online codes-- are you sure that translates okay into JS?

It’s not an important part of the code so I’d probably delete that bit.

Looks like it could be important in the python local code, though:

Okay, here is my solution without pop or join:
At the beginning of the experiment, in my JS-only code, I have
isPyExp = false;
and in a Python-only code block, I have
isPyExp = True
I also have a line to define which keys I want to accept:
allowedKeys = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v', 'w','x','y','z']

At the beginning of my routine, I define:
refined_response = ''

then in the ‘Each Frame’ tab, instead of the above code, I have this:

L = event.getKeys()
if len(L):
    if 'escape' in L and isPyExp:
        core.quit()
    else:
        for i in L:
            if i in allowedKeys:
                refined_response = refined_response + i
            elif i == 'space' and len(refined_response)>0:
                refined_response = refined_response + ' '
            elif i == 'backspace' and len(refined_response)>0:
                refined_response = refined_response[:-1]

You can then have another builder text object that displays $refined_response

Thanks for the hints!

2 Likes