Potential bugs for online experiments

I’m trying to get my online experiment working. In the process of fixing some errors I think I may have come across a couple of bugs.

  1. I don’t think python–>JS conversion works properly when it is written in a non-code component. For example in a text component I wanted to print a message containing the number of trials completed. I typed something along the lines of $"completed " + str(trials.thisN) + " trials". When I went to run this online I was given the error: ReferenceError: str not defined. Creating a code component to assign a variable equal to the above expression, and then referencing that variable in the text component, solved the problem. The same issue occurred when I was making use of the expInfo dictionary. I have a version number field in this, so in a trials loop I reference $"conditions_" + str(expInfo['version']) + ".xlsx". That also gave an error.

  2. At the start of each trial iteration I have a routine that gives the option to rest after a certain number of trials. The first component of the routine is a code component that checks to see the number of trials completed and optionally either skips the routine or continues it and gives the chance to rest and continue upon pressing a button. This doesn’t give an error but instead it doesn’t skip the routine as intended - it actually just shows a blank screen at the start of each trial which happens to be terminable using the same button to terminate the rest period. So I guess there is some problem with the continueRoutine = False command.

The experiment was working find locally, but gave errors when I tried to run it all online. Problem #1 isn’t too much of an issue and my fix worked. But problem #2 is a bit of a problem for me because I really need to present breaks, and my trials are supposed to run regardless of a response. But at the moment there is the blank screen where subjects would need to press space on each trial in order to continue to the next.

Is there any way to fix this and stop the online version from ignoring the continueRoutine=False command?

1 Like

I fixed #2 by simply pasting the code component from beginning of the routine to each frame after seeing in another thread that JS resets continueRoutine = True on each frame.

Don’t use functions for component parameters.

Do define the value you want to use as a variable in code (so it can be auto translated) and then use the variable name in the component itself.

Thanks for the resource. I see that there are known issues with colour too, and I’m having a problem with this now. I set the RGB values in my excel conditions file as python lists, but for Pavlovia this causes the following error:

Unfortunately we encountered the following error:

* when defining a color
* **unknown named color: [-1.0, 0.13725490196078427, 1.0]**

Try to run the experiment again. If the error persists, contact the experiment designer.

Ideally I need to specify these values in the file as opposed to a code component in the experiment itself. I did the latter in an older version but it led to some other JS issues, so I decided to just put them into the file itself. I assume this would work if I didn’t use RGB values but just used the string colour name, but this wouldn’t be ideal. Is there something I can do to handle this?

1 Like

@fffrost when you created a code component to fix problem #1, where did you write it? I tried putting it in the begin routine section but it is not counting correctly (I previously had it in a text component for the offline version)

There were some issues making this work because of the javascript. I wanted a break so I defined a separate break routine called trial_rest of something, and then I put something along the lines of the below inside the Each Frame tab. Normally you could do in begin routine, but for the online version to run it has to be in each frame because of JS.

rest_msg = "Completed " + str(TRIAL_N+1) + " of " + str(n_total_trials) + " trials.\n\nPress [SPACE] to continue..."

if (TRIAL_N > 0) and (TRIAL_N % (n_total_trials / 2) == 0):
    print("Break time")
    continueRoutine = True
    continueRoutine = False

A couple of variables might not be necessary but I was a bit lazy so I defined TRIAL_N and n_total_trials in the begin experiment tab to keep track of these, and I increment them in End Routine in a code component on my trial (hope that makes sense). Either that or I had some other reason to use them, maybe trials.thisN wasn’t working…