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.
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
Hey,
Been a while since I posted here - just kind of lurking now - but I’m fairly certain that the randint is the one from numpy where it is exclusive of the max. Been in since like version 1.70.00 or something (check the changelog).
In the transpiler.py, there was a commit to fix the randint translation to remove the upper limit inclusivity (ie to make your autoTranslated code exclude the upper limit, similar to the numpy.random.randint) - this can be seen here .
I’m assuming this will make i…
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.
Hadeel_Haj-Ali:
random = Math.random
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