Variable in Selected Rows is not defined when running online in Pavlovia

Description of the problem:

I have a loop that runs one time and for each participant, one random item is chosen out of 13 items defined in the excel file:

So, I added a code component at Begin Experiment, and it goes as follows:

useRow = randint(0,14)
useRows = str(useRow)+":"+str(useRow+1)

Then, in Selected Rows of the loop I added the variable $useRows.

image

When running online in Pavlovia, I get the error message:“useRows is not defined”.

Hello,

where did you add the code-component? Try putting it in a routine before the loop.

Best wishes Jens

Hi,

Thank you for your reply. I added the code in Begin Experiment just before the loop, and now I get a new error message : " randint is not defined". I tried adding " import randint " at Begin experiment and it still won’t work

Hello,

do not import libraries for an online-experiment. PsychoPy adds all libraries available on PsychoJS. Look here for a way to use randint

Best wishes Jens

1 Like

I searched the forum and accordingly, using import is not recommended in JS. So I edited my code:
random = Math.random
useRow = random(0,14)
useRows = str(useRow)+":"+str(useRow+1)

Now it works fine online in Pavlovia, but not offline in Psychopy.

Put

randint = function(min, maxplusone) {
  return Math.floor(Math.random() * (maxplusone - min) ) + min;
}

in code_JS as per my 2020 crib sheet and then useRow = randint(0,14) for a number 0-13.

1 Like

Thank you!!