Description of the problem: I am trying to build a digit span task (forward and backwards), and it works locally but not on pavlovia. does anyone know what the error means? I have checked the console and i am unsure what it means. Here is a screenshot of this:
you can see the error at the bottom, as well as the line it corresponds to on the top right. Any help would be appreciated!
Do you have screen_text = ‘’ in Begin Routine or Begin Experiment?
hi yes, i have it in multiple routines: ill attach screenshots of them below: they are the same in the other routines
Those code components are Py = Python only. Change them to Auto to generate the JS code.
thanks for that! was a silly error on my end! that has helped however i am getting another error now:
i have tried to find that within psychopy and tried changing the code as i am not using backspace but when i delete it it comes up a syntax error for the JS code. Ill attach the code below:
i think it might be referring to that screenshot. i originally planned to allow backspacing but not anymore due to the experiment changes so in my key response tab i deleted the backspace…but in the code im unsure what to do
You have to check “if key_resp_4:” before checking its keys. The keys are undefined until a key is pressed.
i am unsure what that means? im not really versed with coding. Do you have any tips please?
I have tried to understand what that means and change it in the code, but I am still getting the syntax error. I think its referring to line 1 of the py code? But I’m unsure what to do so that I have no backspace - it is no longer part of the experiment so would I just delete all the text from lines 1 and 2? Because I am still getting syntax errors on the js side
If you copy and paste your current Python code I can make the edit I mean.
Oh! thanks for the clarification. This is the current python code in the each frame tab:
if(“backspace” in key_resp_4.keys):
key_resp_4.keys.remove(“backspace”)
if(len(key_resp_4.keys) > 0):
key_resp_4.keys.pop()
elif(“return” in key_resp_4.keys):
key_resp_4.keys.remove(“return”)
screen_text = ''.join(key_resp_4.keys)
thisExp.addData("recall_resp", screen_text)
continueRoutine = False
screen_text = ‘’.join(key_resp_4.keys)
I have another routine with the same (one is the practice trial and the other one is the actual trial), but once i know for this i can change the other one
Try the following
if key_resp_4:
if "backspace" in key_resp_4.keys:
key_resp_4.keys.remove("backspace")
elif "return" in key_resp_4.keys:
key_resp_4.keys.remove("return")
screen_text = ''.join(key_resp_4.keys)
thisExp.addData("recall_resp", screen_text)
continueRoutine = False
elif len(key_resp_4.keys) > 1: # Why was this > 0 ?
key_resp_4.keys.pop()
if len(key_resp_4.keys) == 1:
screen_text = ''.join(key_resp_4.keys)
Hi,
Thanks for this!
However, now in the builder when i try to type in the response, it only allows me to type one number, and not any more than that. As it is a digit span task the numbers go up (so first recall 3, then 4, etc depending on whether they get it correct or not), but using this code it only allows me to press one number in response to all the trials. so if the presented numbers are ‘3, 5, 7’ i can only press a single number and then no other key that is pressed shows
i tried the same code for by other routine (changing the name of the key_resp) and it is the same outcome
Try
if key_resp_4:
if "backspace" in key_resp_4.keys:
key_resp_4.keys.remove("backspace")
if len(key_resp_4.keys) > 0:
key_resp_4.keys.pop()
elif "return" in key_resp_4.keys:
key_resp_4.keys.remove("return")
thisExp.addData("recall_resp", screen_text)
continueRoutine = False
screen_text = ''.join(key_resp_4.keys)
this code now allows me to run the task properly locally, thank you very much. however, pavlovia is still having problems reading the code
i think it might be due to my last routine (i have three. the first two are forward trials so i used the code you sent for them two and they both work perfectly), but the last routine is where the response has to be said backwards. so if ‘3, 6, 5’ is presented, the participant would respond with ‘5, 6, 3’ so the code is different for this. this is what i have for the code:
if(“backspace” in key_resp2_2B.keys):
key_resp2_2B.keys.remove(“backspace”)
if(len(key_resp2_2B.keys) > 0):
key_resp2_2B.keys.pop()
elif(“return” in key_resp2_2B.keys):
key_resp2_2B.keys.remove(“return”)
screen_text = ''.join(key_resp2_2B.keys)
thisExp.addData("recall_resp", screen_text)
continueRoutine = False
screen_text = ‘’.join(key_resp2_2B.keys)
i am wondering if i could use the same code you sent for this as well? (of course by renaming the key_resp to be associated with this routine)
Did you forget if key_resp2_2B: ?
This is the code for another routine (the backwards part of the task). Would I need to add ‘ if key_resp2_2B’
If you copy and paste your current Python code I can make the edit I mean.
yes, this is the code:
if(“backspace” in key_resp2_2B.keys):
key_resp2_2B.keys.remove(“backspace”)
if(len(key_resp2_2B.keys) > 0):
key_resp2_2B.keys.pop()
elif(“return” in key_resp2_2B.keys):
key_resp2_2B.keys.remove(“return”)
screen_text = ''.join(key_resp2_2B.keys)
thisExp.addData("recall_resp", screen_text)
continueRoutine = False
screen_text = ‘’.join(key_resp2_2B.keys)