I am using a code component to break a sentence (sentence variable from my conditions file, containing a list of sentences) and present it word-by-word. This code works fine offline, but gives an error online:
TypeError: Cannot read properties of undefined (reading ‘shift’)
To translate my Python code to JS, I made some manual changes using @wakecarter crib sheet. However, this does not help:
Python:
if trials.thisN == 0:
sentence_list = sentence.split()
current_word = sentence_list.pop(0)
Thank you very much for trying to help, this is much appreciated! I am really struggling with this experiment.
I am not sure, but maybe the error develops because JS does not understand that my variable is an array. In your experiment, in JS you defined numbers (num) as an array containing numbers. I have a similar variable, but I’m not sure how to define it as an array. Because it’s an excel column containing 40 different sentences, not one array I can define in my code component.
That’s interesting because the experiment runs as intended, offline as a Python-based experiment, offline as a JavaScript-based experiment in a browser, and online. I have just tested it. So I don’t know why the script doesn’t work in your case. By the way, I am using 2022.2.4.
Thanks! I also switched to 2022.2.4, I am not getting the error now, but instead of presenting my sentences, Pavlovia presents “Hello world”, which is extremely strange.
Can this be related to how I store my “sentence” variable in xlsx file?
No, I don’t think so. Did you look at my toy-example? Did my toy-experiment run? When yes, just change the Excel-file in my toy-experiment and give it a try.
are you sure it runs online? After searching the hello world issue on this forum, I found that variables defined in the conditions files can not be manipulated online. That is, my variable “sentence” cannot be split into words online: Error when importing conditions in nested loops
Which version are you using?
As much as I know, trials.thisN doesn’t work on older versions online (not sure about new versions).
What you can do is create a new variable that is equal to 0. Then each time the routine start/end, increase this variable by one.
Thank you for all your help!
I’ve been giving it a try all day yesterday, and it only worked today, when I uploaded (not switched to) and installed the newest PsychoPy version…