Experiment does not run online

Hi there,

I have a sentence comprehension experiment that runs on PsychoPy but when I upload it to Pavlovia, it gives me this error: "

I read some related posts here and the problem seems to have to do with a code component which contains both “.draw” and “win.flip()” functions, both of which seem to cause problems when converting to JS code. Here’s my code component in PsychoPy:

words = Sent.split()
Sentence.setText("+")
for frameN in range (30):
Sentence.draw()
win.flip()

for word in words:
Sentence.setText(word)
for frameN in range (18):
Sentence.draw()
win.flip()

for frameN in range(12):
       win.flip()

I have already tried replacing all the instances of “win” with “psychoJS.window” and also all the "draw"s with “.setAutoDraw(True)”, but these did not fix the problem.

Does anyone know how to fix this problem?

Many thanks in advance!

Hossein

Off the top of my head. I think you need to change .split() to .split(‘ ‘)

Also try .text=“+” instead of.setText(“+”)

Thank you for your reply! I made these two changes but I again get the same error message. I changed the code in the JS side of the code component window.

None of your code components should ever contain win.flip(). Builder controls flipping the window buffer itself. If you call it manually, you will disrupt the drawing cycle and careful timing system in Builder-generated scripts.

win.flip() should only be used by people writing their own experiments directly in code (who are responsible for their own screen updating and timing), rather than people using Builder, which does that stuff for you. So I’m guessing this code came from a custom script, rather than being intended for a Builder code component. You’l need to describe what you want to achieve and we can give hints as to how to do it with Builder’s own features.

Thank you for your reply. Yes, I took this code from Stack Overflow and adjusted it to meet my needs. I want to present some sentences one word at a time such that each word stays on the screen for 300ms followed by 200ms of blank screen. This is a behavioral follow-up to an EEG study and we want to keep the design the same. So, it’s important that the timings are correct.

Thank you so much in advance for your help and please let me know if you need more information!

–Hossein

OK. To do this you need a two-loop arrangement. Presumably you currently have a loop that is connected to your conditions file and that gets a variable from that file that I’ll call sentence. i.e. this loop will run once per trial, presenting one sentence. Insert another loop inside that trial loop. This will run once per word (i.e. multiple times per trial). Below I’ll refer to this loop as being named word_loop. Give this loop an nReps number that will safely exceed the number of words in any possible sentence (e.g. 99).

Insert two text stimuli in your trial routine. One contains just a space character and is set to display from t == 0.3s until t == 0.5 s (i.e. to be your blank inter-stimulus interval).

The other is the one to display the word. Set it to last from 0 to 0.3 s and to contain a variable called, say, $current_word, set to update on every repeat.

Above the text components, insert a code component. In its “begin routine” tab, put something like this:

# at the beginning of each trial, extract the 
# individual words:
if word_loop.thisN == 0:
    word_list = sentence.split()
    num_words = len(word_list)

# check if the sentence has ended. If so, 
# go on to the next trial
if word_loop.thisN == num_words:
    word_loop.finished = True
    continueRoutine = False
else: # display this word:
    current_word = word_list[word_loop.thisN]

I don’t know how you want to save your data. If you want a row of data associated with each word, make sure that word_loop has Is trials selected. If you want just one row of data per trial, de-select that.

PS Oops, I’ve just looked back and seen that your question is about running online - whereas I’ve given you a Python solution. It would need translating to JavaScript, and I’m not sure how referring to loops works there - I think they are all just called trials?

Thank you very much for your elaborate reply, Michael. I really appreciate it. I actually wrote another code that ran successfully on my laptop but again failed to run on Pavlovia. The code only consisted of if-statements, and I was surprised it didn’t run online. I gave up on Pavlovia… working on Ibex Farm now.

Anyway, thanks again!

Hossein

Michael, I am trying to apply your solution to run my experiment online.
For some reason, I get * TypeError: Cannot read properties of undefined (reading ‘99’)

Here is the Python code:

if trials_4.thisN == 0:
    word_list = sentence.split()
    num_words = len(word_list)


if trials_4.thisN == num_words:
    trials_4.finished = True
    continueRoutine = False
else: 
    current_word = word_list[trials_4.thisN]

and JS translation:

if ((trials_4.thisN === 0)) {
    word_list = sentence.split(" ");
    num_words = word_list.length;
}
if ((trials_4.thisN === num_words)) {
    trials_4.finished = true;
    continueRoutine = false;
} else {
    current_word = word_list[trials_4.thisN];
}

I’ve been struggling with this similarly simple issue for a while, any help is highly appreciated!

Please could you check the Browser console to work out which line is giving the error?