TrialHandler Pavlovia

URL of experiment: Sign in · GitLab

Hello,

I use Pavlovia for the first time and I have some trouble to convert a code component from Python to JavaScript used to present four subtasks in a random order.

It is this part of the JS code which does not work:

EM = new TrialHandler({
** psychoJS: psychoJS,**
** nReps: 1 if cond[id] == EM else 0, method: TrialHandler.Method.RANDOM,**
** extraInfo: expInfo, originPath: undefined,**
** trialList: undefined,**
** seed: undefined, name: ‘EM’**

With this error:
Uncaught SyntaxError: missing } after property list Exp1Final.js:1740:15
note: { opened at line 1738, column 26

I think the problem comes from “nReps: 1 if cond[id] == EM else 0”. Despite all documentations available online to convert Python to JS (thank you for that btw!), I do not understand how to fix it.
I already had huge difficulty to randomize subtask order with Python, I wish I could keep this code for online experiments…

I hope these explanations are clear. You can find more explanations about code components below.
Let me know if you need further explanations.

Thank you a lot if you can help!


Explanations from builder

I add 3 code components to couterbalance the four subtasks:

  1. At the begening of the task to shuffle the tasks:

id = 0
cond=[“SM”,“EM”,“EF”,“VP”]
random.shuffle(cond)

  1. For every loop in nReps: “id” position with “1 if cond[id] == “SM” else 0”
    For example, if id = 0 and SM is in the first place of “cond”, SM will be run.

  2. At the end of the last loop: id = id +1

Thus, the four loops are played four times but each task runs when id = cond.