I’d like to multiply a textbox input and return the first 5 digits of the result on the dispaly, but I encounter the following errors while running it online.
in the end routine of a code component:
returnValue = 12345*int(textboxCode.text)
returnValueStr = str(returnCode[:5])
thisExp.addData(‘returnvalue’, returnValue)
Problems:
1- returnValue is saved correctly in the results csv file, but it does not update during the experiment: if I try to display it, the screen shows the initial value I assign to it when I initialize the variable.
2- autotranslate returns returnValue.slice(0, 5) , which gives error when I run it in Pavlovia ( TypeError: returnValue.slice is not a function)
if you put everything in the End Routine tab, the text-component displaying the returnValue will not be updated. The routine ends. Try putting everything but thisExp.addData in the Each Frame tab.
Thanks for your reply.
I tried to put the part:
returnValue = 12345*int(textboxCode.text)
in the “each frame” tab but still it doesn’t work (variable does not update).
One solution I have found is to create a variable and then append textboxCode.text to it:
response=response.append(textboxCode.text)
which gets translated in JS as
response = response.push(textboxCode.text);
(quick note: I have to manually write in the code part the translation because Array.prototype.append = [].push; in the begin experiment tab makes the experiment crush)
However, while I can succesfully display $response as a text in the next routine, it seems that I cannot apply any tranformation.
For example:
in the code component:
response=response.append(textboxCode.text)
responseTrans=12345*int(response)
responseTrans=str(responseTrans)
in the text field:
$response → the textboxCode.text is successfully printed
$responseTrans → nothing is displayed
I can’t “speak” JS so I need access to the PsychoPy-script which is not included in your repository. I usually “program” everything in PsychoPy, let it autotranslate and edit the few (hopefully) places which do not work in PsychoJS.
this version runs locally. I hope it runs in the way you intended it to do. However, the program does not run on-line. The error that PsychoJS throws is state.toLowerCase is not a function. You find some information concerning the error in the post just mentioned. I have been using PsychoPy 2020.2.10. I suggest opening a new thread for this.