Pavlovia- TypeError: win is undefined

URL of experiment: private experiment

Description of the problem: Hello everyone, when i try to pilot my experiment on Pavlovia, I get an TypeError: win is undefined error. I do not have a code component in which I specify that I want the window to be full screen, I’ve only checked the option for full screen in the Experiment settings. Do I need to add an additional code component regarding the screen? Thank you in advance.

It doesn’t necessarily have to do with fullscreen, but this error most likely indicates that there is a code component that, in Python, refers to the visual.Window object PsychoPy uses for local experiment runs. For example, if you define a visual stimulus inside a code component, or change the background color, or call win.flip(). None of those work in PsychoJS (the code that runs on Pavlovia), in fact nothing that refers to the “win” object will work in PsychoJS.

So, what code components do you have currently?

Thanks for your reply!
I will briefly explain my experiment because I think it will help to understand it better: In my experiment, participants go through a word list while background music plays. The music continues until all the words have been presented and then stops. After that, a text component appears. This happens a total of three times. Once everything is finished, there is a final text.

There are a total of three code components: one in the ‘trials’ routine (where the words are presented), another in the ‘text’ routine (after all the words have been presented), and a final one in the last ‘endText’ routine (the final text).

The first code component in my routine trial is:
Begin experiment:
background_sound = sound.Sound(‘mysound.wav’)
sound_started = False

Begin routine:
if not sound_started: # “If the sound has not started yet.”
background_sound.play()
sound_started = True # “Set the variable to True so that the sound does not restart.”

text Routine:
Begin routine: background_sound.stop()
End routine background_sound.play().

endText routine:
Begin routine: background_sound.stop()

Thank you in advance!

I would recommend that you create your sound object with a component and then control it in code.

Thanks for your reply. I tried (I didn’t fill in anything for the duration, by the way) and it messes up the whole experiment (text stimuli and fixation cross are presented at the same time and then there is nothing, only the sound and a blank screen.

What version of PsychoPy are you using?

Does it work locally?

I use the PsychoPy 2024.2.4 version and yes it does work locally.

I belatedly realized that something like this is probably the underlying issue: TypeError: undefined is not an object (evaluating 'win._psychoJS') - #2 by jonathan.kominsky

Thank you for your answer. I rebuilt the experiment step by step and realized that without the code components regarding the sound, the experiment works on Pavlovia. I need this sound, and if I insert a sound component into the trial routine, the whole experiment fails because text and sound components cannot be used at the same time as it messes up the order. However, it does not work with a code component either (in Pavlovia).

Have you tried this are are you still trying to create the sound object in code?