My experiment won't run even as a pilot

I have created my first project file on Pavlovia and every time I press ‘Pilot’ to see what my experiment looks like in a browser, it comes up with a white page that says “initialising the experiment” and then after a few minutes the tab closes without running the experiment.
GitLab Id: #73637
If anyone has the time to check it out I’d be really grateful for the help!

Have you looked at my crib sheet (see pinned post)?

You should be able to get a better error message from the console

I used Psychopy to build my experiment because I don’t know how to program. I don’t know Python, so a crib sheet making it easier to convert Python to Javascript (as far as I understand it, please correct me if I’m wrong!) means nothing to me.

I did look at the pinned post, and I can confirm that my experiment runs locally just fine, which is what makes my problem so confusing to me. Do you know of any common errors that prevent an experiment running via Pavlovia that I could check aren’t happening?

Thank you for the response, I really do appreciate you taking the time to help.

Edit: I used the Web Developer tool on Mozilla Firefox and under Web Console it says "Uncaught SyntaxError: expected expression, got ‘,’ " and when I clicked on the link to open the .js code for my experiment there was a stray comma highlighted. I deleted this comma from my local .js files and replaced the .js files on Pavlovia with the edited ones. It still comes up with the same message. Also, when I try to open my .js files on my PC it comes up with the error message “Syntax error - Microsoft JScript Compilation Error” (I had to get around it by using right click + Edit to remove the stray comma).

Editing the JS file directly is rarely the best approach (unless you know why you can’t do it via Builder)

The description of your original error sounds like it might be a blank text component that needs to be replaced with a space. Is that possible?

If you have an experiment with no Python code components, you may still have Python code in other components or you might have variable components (which are a form of code component you should avoid for online use).

P.S. The crib sheet is for people using Builder not Coder, which I would strongly discourage for online (unless you are an expert JavaScript programmer, in which case you should probably be using PsychoJS directly.

I did have some blank screens, so I added a fixation cross to each of them so that the text component would no longer be blank. I then had an error message on Python about my font family not being assigned, so I added single quote marks around my font family for every text element. I also spent some time creating an SSH key pair and adding it to my profile (I’m still not clear on what that does exactly, but it seems important). I noticed in the crib sheet you mentioned a new error with the syntax for allowing a single key response, so I fixed that by adding square brackets to all of my keys when I only allowed the spacebar to be pressed.

After all of that, the syntax error being displayed by web developer changed, and I tried to fix the issue in Builder but could only do so much. So I removed a surplus comma from the .js and it ran! Sort of. It displayed the screen where I could type my participant number in, and when I clicked okay I got a brand-new error message:
ReferenceError: assignment to undeclared variable frameDur

I feel like I’m getting closer to making it run.

Edit: It seems that my experiment doesn’t convert well to JS. I’ve discovered that the error message seems to indicate that the .js code doesn’t have any of the items I’ve added to my experiment in Builder as declared variables. I could go in and append ‘var’ to every text box, button, image and form in my experiment, but I’d really rather not. I don’t understand why it’s done this.

Editing the JS to remove a comma probably just moves your syntax error somewhere else. frameDur is normally properly defined (as 60) in the standard code.

I can’t think of any reason to add lots of vars. If you get an error x is not defined you just type x = 0 (or ‘’ or []) in a Begin Experiment code tab.

I put a space in blank text components to keep them invisible.

If you have an experiment with no code components that runs offline but doesn’t work online, you should check whether you are using components that haven’t yet been implemented online.

I don’t know what an SSH key pair is but it feels like you are introducing more errors than you are fixing.

PS Did you also read the quick start guide also linked from my pinned post and the crib sheet?

Thanks for the crib sheet, I was able to fix a few basic errors that I never would have known about!

In the end, I created a new project folder and re-created my experiment frame by frame until it no longer ran on Pavlovia. Turns out I can make the Forms component run perfectly well locally, but it won’t load on Pavlovia. So I just made it so that all questions in the form could be answered by writing in a textbox, or using sliders, instead of clicking a radio button. Now it works just fine, and I’m having entirely new problems haha.

My project supervisor has suggested that I provide participants with feedback throughout the experiment. The experiment shows two images, asks a question, and the participant responds by pressing a key. If the answer is correct, I would like it to display ‘Correct!’, and if the answer is incorrect, I would like it to display ‘Incorrect!’ and play a tone. Of course, I have no idea how to do this. If you could advise me again I’d be grateful, but if not then I’ll start a new thread for the issue.

Thanks again for your time :slight_smile:

My crib sheet does say not to use forms…

For feedback you need to check if key_resp.corr == 1:

I would set up the tone earlier as a sound component that doesn’t get heard (because the routine ends before it starts). Then set the feedback text to Correct else Incorrect and sound.play()

Yeah I saw that on the crib sheet, but I really wanted to try to find a way to make it work because it’s a much more intuitive set-up for the questions I needed my participants to answer.

I have a text component ‘Resp1_text’ that’s set to last 10s and a key component ‘Resp1_key’ that accepts the A and L keys being pressed, stores all answers (although the correct answer is set to L) and lasts 10s. I set up my sound component ‘sound_1’ to start after 20s, as the routine would have ended by then.

I added a code component with this in ‘Each Frame’:
if Resp1_key_.corr == 1:
message = visual.TextStim(win, text=“Correct!”)
message.draw()
core.wait(2)
else: message = visual.TextStim(win, text=“Incorrect!”)
message.draw()
sound_1.play()
core.wait(2)

But the experiment just crashes after showing the previous routine, it doesn’t show any of my components at all. I’ve tried many, many different iterations on this using the Psychopy programming guides and guides by other users but everything yields the same result. I’m very confused!

I always set up my text components as components (set to space constant)

Then just set text_component.text=‘Correct’ instead of trying to set up a text component from scratch in code.

PS You seem to have missed the bit in my crib sheet about not using draw or wait. Draw is okay but only if you understand that the command is only to draw for that frame…I normally setAutoDraw(True) instead

I know that it must be irritating to a more experienced user to see all of these basic mistakes when you’ve put the effort in to write a crib sheet explaining how to fix them, but as I’ve said before- I’ve never programmed anything before, ever. And it’s a 22 page document. I refer to it as much as possible, and it has been really helpful, but I’m still going to miss things because it’s hard to know what’s relevant to my build, and I don’t know what I’m looking for half the time because I have no idea what the error could be.

I’ve changed the code as you suggested:

if Resp1_key_.corr == 1:
text_component.text=‘Correct’
setAutoDraw(True)
else: text_component.text=‘Incorrect’
setAutoDraw(True)
sound_1.play()

With text components named ‘Correct’ and ‘Incorrect’ set up to start after the routine has ended, just like the sound component. Unfortunately, it didn’t seem to change anything at all. It still crashes without displaying anything from my response routine.

Edit: I’ve just noticed that I’m now getting a lot of error messages, and I wasn’t getting any at all before.


The first five lines of the second screenshot can be ignored, it was difficult get get the whole list of errors in one shot!

I also sometimes spend time debugging something only to discover I’ve already put the solution on my crib sheet…

A tip when posting code on this forum. Please use the preformatted option so we can see your indents.

e.g.

if Resp1_key_.corr == 1:
     text_component.text='Correct'
else: 
     text_component.text='Incorrect'
     sound_1.play()

(edited to remove smart quotes)

This assumes a text component called text_component which has a space as the contents, not separate ones called Correct and Incorrect. There’s no need to add text_component.setAutoDraw(True) if the text component is in the same routine. There’s also no need to start it late, since it will only change if the above.

The above code would work best at the start of a separate feedback routine so you could set the duration of the text compoentn to be 2 seconds.

Why is Resp1_key storing all responses? Don’t you want it to end the routine?

So I created a separate feedback routine, removed setAutoDraw(True), and the text components no longer start late. This is what the code looks like now (thanks for the tip on formatting it properly!):

if Resp1_key.corr == 1:
   text_component.text ='Correct'
else: text_component.text ='Incorrect'
sound_1.play()

I have brand-new error codes appearing now:

Oh, and Resp1_key is saving all responses because this is one response to one pair of stimuli, and I need to know if the response is correct/incorrect so that I can calculate response accuracy at the end of the experiment.

text_component is not defined because either your text component isn’t called text_component, or you’ve defined it later than the code component.

I’m not sure I understand your reason for saving all responses. Saving first/last response saves one response per trial. I would be separately adding 1 to a total score if the response was correct if I wanted to feed the accuracy back to the participant or use it later.

Changing text_component to the name of my actual text component made the feedback components appear…but they’re appearing all at once no matter what I press.

Please could you show your current code and a screenshot of the routine?