Str error when piloting experiment

I created an experiment in PsychoPy Builder with snippets of code with Code components. The experiment runs fine in PsychoPy, but when running on Pavlovia I get the following error message after the initial participant ID window: “Unfortunately we encountered an error: ReferenceError: str is not defined”

I used string functions in text components to display items from arrays.

Github folder if you want to have a look at the program (versions 02 and 03 of the experiment):

Any help is appreciated. Thank you.

Nabil

Please could you show the Python and JS code where you have str. If it’s in a text component then you probably need to define the text in a code component (so it can auto translate) and then just pass that variable to the text component.

Best wishes,

Wakefield

Hi Wakefield,

Do you mean I should create a text variable that has all the information required and just display that variable in the text field of the text component?

This is what’s in the text field of the component:
$‘Identify the colour while ignoring the word\n\nUse the following keys to respond:\n\n’
+str(responseKey[0])+’ - ‘+colourList[0]+’ ‘+str(responseKey[1])+’ - ‘+colourList[1]+’ ‘+str(responseKey[2])+’ - ‘+colourList[2] +’\n\nPress any key to start’

and the converted JS code from Pavlovia:

text = new visual.TextStim({
win: psychoJS.window,
name: ‘text’,
text: ‘Identify the colour while ignoring the word\n\nUse the following keys to respond:\n\n’
((((((((((((+ str(responseKey[0])) + ’ - ') + colourList[0]) + ’ ') + str(responseKey[1])) + ’ - ') + colourList[1]) + ’ ') + str(responseKey[2])) + ’ - ') + colourList[2]) + ‘\n\nPress any key to start’),
font: ‘Arial’,
pos: [0, 0], height: 0.04, wrapWidth: undefined, ori: 0,
color: new util.Color(‘white’), opacity: 1,
depth: -1.0
});

Correct. Put msg=‘Identify the colour while ignoring the word\n\nUse the following keys to respond:\n\n’
+str(responseKey[0])+’ - ‘+colourList[0]+’ ‘+str(responseKey[1])+’ - ‘+colourList[1]+’ ‘+str(responseKey[2])+’ - ‘+colourList[2] +’\n\nPress any key to start’

in a code component and then use $msg in the text field

Thank you.

Hello, I had the same problem and fixed it using the same method. However, when I run it online, the message doesn’t display and I get a blank screen. If I click spacebar it continues onto the rest of the experiment so it seems to be an issue with displaying the text. Any advice on how to fix this would be greatly appreciated.

One of the mistakes I make is presenting black text on a black background.

Alternative issues are the font size or msg being set after the text had already been displayed.

My text is white on grey and font size the same as other screens that are displaying correctly (.03). I have my text, response and code components in the same routine.

In the Begin Experiment section of the code I have:
Condition=""
msg=""

and in the Begin Routine section I have:

if Condition == 0:
msg=“Level” +str(BlockNumber) +"\n In the first part of this experiment you will see a green or a blue picture on each trial.\n\n If the picture is blue, press the left key.\n If the picture is green, press the right key.\n\n Try your best not to make any mistakes!\n\n Please ignore the metronome for now!\n\n Press the spacebar to start!"
if Condition == 3:
msg= “Level " +str(BlockNumber) +”\n\n Great work! Let’s do that again!\n\n This time, please ignore the metronome. Just sort the pictures.\n\n Remember to try your best not to make any mistakes!\n\n Press the spacebar to start!"
if Condition == 1:
msg= “Level " +str(BlockNumber) +”\n\n Great work! Let’s do that again!\n\n This time, you will have to say ‘tick, tick, tick’ whilst sorting the pictures, to the beat of the metronome!\n\n Remember to try your best not to make any mistakes!\n\n Press the spacebar to start!"
if Condition == 2:
msg= “Level " +str(BlockNumber) +”\n\n Great work! Let’s do that again!\n\n This time, you will have to tap your foot whilst sorting the pictures, to the beat of the metronome!\n\n Remember to try your best not to make any mistakes!\n\n Press the spacebar to start!"
if Condition == 11:
msg= “Level " +str(BlockNumber) +”\n\n Well done! Now you are going to sort 5 different PICTURES. You will have to learn the correct response to each picture. To begin with, you will have to guess (I won’t tell you what the correct responses are).\n\n Remember to try your best (even though you will make some mistakes to begin with)!\n\n During this block, you will have to say ‘tick, tick, tick’ whilst sorting the pictures.\n\n Press the spacebar to start!"
if Condition == 12:
msg= “Level " +str(BlockNumber) +”\n\n Well done! Now you are going to sort 5 different PICTURES. You will have to learn the correct response to each picture. To begin with, you will have to guess (I won’t tell you what the correct responses are).\n\n Remember to try your best (even though you will make some mistakes to begin with)!\n\n During this block, you will have to tap your foot whilst sorting the pictures.\n\n Press the spacebar to start!"
if Condition == 21:
msg= “Level " +str(BlockNumber) +”\n\n Well done! Now you are going to sort 5 different SYMBOLS. You will have to learn the correct response to each picture. To begin with, you will have to guess (I won’t tell you what the correct responses are).\n\n Remember to try your best (even though you will make some mistakes to begin with)!\n\n During this block, you will have to say ‘tick, tick, tick’ whilst sorting the pictures.\n\n Press the spacebar to start!"
if Condition == 22:
msg= “Level " +str(BlockNumber) +”\n\n Well done! Now you are going to sort 5 different SYMBOLS. You will have to learn the correct response to each picture. To begin with, you will have to guess (I won’t tell you what the correct responses are).\n\n Remember to try your best (even though you will make some mistakes to begin with)!\n\n During this block, you will have to tap your foot whilst sorting the pictures.\n\n Press the spacebar to start!"

and $msg in the text display box and it gets the condition variable from an excel file

What is strange is that it runs perfectly fine locally but just doesn’t display anything online.

If the code component above or below the text component.

Personally I now tend to have the text component (e.g. text_1) a space set to constant and then use text_1.text= instead of msg=

I’ve encountered similar issues before, where the experiment runs fine locally but some components are ‘ignored’ in Pavlovia but does not throw up an error. The issue in those cases were because the equivalent JS function was not supported in Pavlovia. So it was not identified as an error (since it’s a legal line of code), but does not get executed in the online experiment. So it might be worth checking if this is the case.

Forgot to add: could the issue be the initialising of the variable to be “” ? If JS doesn’t recognise that as null, then it will not satisfy any of your if conditions.

Three possibilities:

  1. Make sure you use " not intelligent “quotes”.
  2. Set msg=" " instead of msg=""
  3. It’s possible that Condition is string rather than numeric so use if Condition == '0' instead of if Condition == 0.

I would recommend that you use elif instead of if in each case.

Try print(‘Condition’,Condition,’ msg’,msg) to check whether the msg is being set correctly.