psychopy.org | Reference | Downloads | Github

A few questions about PsychoPy online

URL of experiment:
https://pavlovia.org/run/roberto.petrosino/maskedpriming/html/

I am playing around with PsychoPy for my next priming experiment and I have a number of things to add to my experiment, but I do not know how to, since PsychoPy online seems to have access to the edits from the Builder only. Basically, all the questions below stem from a single question being:

Is it possible to use the Coder to edit the feature of an online experiment?

If yes, how do I do that?
If no, I guess I’ll need to come up with some work around - so please read my questions below. :slight_smile:

  1. I would like to have a break inside my loop loop that pops up when half of the trials have been presented. So, I have created a Code component in my break_2 routine and added the following lines in the Begin Routine tab:
if loop.thisTrialN not in [ int(loop.nTotal/2) ]:     
    continueRoutine = False #take a break after first half of stimuli has been presented

text_break.text = "You can now take a short break.\n\n There are" + str(loop.nRemaining + 1) + "words left. \n\n When you are ready, press 'SPACE' to resume the experiment."

Weirdly enough, this does not seem to work properly with PsychoPy online only, while it does with the local PsychoPy software. In PsychoPy online, just the text

placeholder

(which is what I put in the text box in the settings of the text component of the break_2 routine) appears after every word.

  1. Is there a way to add info about timing of the routines? Michael and I had a long conversation on how to implement this in the Coder, but now I feel like I can’t implement the edits that I wanted in the online version of the experiment. Checking the timing of the routines would be crucial nonetheless, so I wonder whether there is any work around I can implement in the Builder.

  2. Is there a way in the Builder to order the items of the dialog box in a customized order?

  3. Right now, pressing a button on my keyboard makes a beep. Is there a way to avoid this automatically (i.e., without asking participant to turn the audio off)?

Thank you all in advance!

To the first part about adding code, yes, Code Components now allow you to add code in “both” Python and JS alongside each other. You could alternatively export the script into html/JS and then hack the script (the way you’ve been doing in Coder by the sounds of it) but my strong recommendation is that you don’t (either in Python or in JS). Try to get the code into code components instead. As you’re finding, rewriting an entire Python script in JS is a huge task.

  1. I think the equivalent JS would be this (but I’m no JS expert):
 if loop.thisTrialN != int(loop.nTotal/2) :     
     continueRoutine = false
  1. I think this would be roughly the same (but do it in Code Components not in the large script)
  2. In the next version of PsychoPy (3.1.0) the info dialog will maintain the order you give in the Settings panel for Python3 backend and will continue using alphabetical order for the Python2 backend. For the PsychoJS engine I don’t know off the top of my head what determines the order. If it needs fixing in some direction I’m sure that can be arranged.
  3. I have no idea why that would be the case. I’ve run quite a few studies online now and never heard any beeping.

Jon

Many thanks for your message, Jon.

So, if I am understanding correctly, the general message is: the Code Components within the Builder will work as long as it is written in JavaScript (and not in Python). Is that right?

Does anybody know how this can be arranged?

I was surprised too. It might be some sort of option that happens only on my Mac.

BTW, I don’t think this is right. The JS syntax is slightly different, so I guess it should be something like:

if (loop.thisTrialN != (loop.nTotal/2) ) {
   continueRoutine = false }

However, this does not work since the PsychoJS trialHandler does not seem to have the equivalent commands. Does anybody know a way around this?

Yes, exactly.

Sorry, yes, I was writing off the top of my head, mostly trying to make sure the Python in syntax was removed.

Could you expand on that? What happens? Certainly the attributes thisTrialN and nTotal do exist:

and I’m pretty sure the Builder-output JS scripts do use contintueRoutine=false in them

You’re right, my bad. I just checked the documentation page (and not script) and I thought you guys were still working on it. Phew ~ it is good that all the functions I need are there!

I am still having trouble translating this in JS because of my ignorance of the language.

if (!( loop.thisTrialN in [loop.nTotal/2] )) {     
    continueRoutine = false; 
} //take a break after first half of stimuli has been presented

text_break.text = "You can now take a short break.\n\n There are " + loop.nRemaining + " words left. \n\n When you are ready, press 'SPACE' to resume the experiment.";

When I run it, the textComponent text_break.text appears after each trial and you have to press SPACE to get to the next trial. See the screenshot below. As you can see, I have also tried to print the variables thisN, thisTrialN and nTotal.

Regardless of how far I am in the experiment:

  1. nRemaining is always 0
  2. thisN is always 10, whereas thisTrialN is always 0
  3. nTotal is always 0.

Can someone help? I think there’s something wrong in my if-statement, but I can’t figure out what it is. Also - is there any sort of Python-JS comparison table I can consult?

I have tried to run the very same experiment from both PsychoPy desktop and PsychoPy online and the output csv files are very different - I am attaching both of them below.

The main difference I have noticed is that the loop.thisN and loop.thisTrialN variables in the PsychoPy online csv file report the same number, which is leading me to think that something is not right. I know nothing about JS, so my code may not be right, but there may also be something that does not work in the definition of trialHandler functions. I would really appreciate if someone could help with this.

PsychoPyDesktop_maskedPriming_2019_Apr_22_1139.csv (1.6 KB)
PsychoPyOnLine_maskedPriming.csv (1.4 KB)

Hi, I have recently come across a problem where I need to translate my custom code to javascript but I do not know how to do this. I put it in to allow participants to have breaks at the specified trial numbers. This is the code:

if loop.thisTrialN not in [53,106,159,212]:
continueRoutine=False

I would really appreciate any help, thank you!

As per my reply on the other thread where you posted the same question, have you tried trials.thisTrialN not in [53,106,159,212] (expect I habitually use trials.thisN rather than trials.thisTrialN)

Hello,

Yes I have tried that and it comes up with a ‘unexpected identifier’ error when trying to export the HTML to upload online.

ERROR: Line 1441: Unexpected identifier in Test Experiment 2.js
ERROR: Line 1437: Unexpected identifier in Test Experiment 2NoModule.js