URL of experiment: Pavlovia
version PsychoPy 2021.1.1
Description of the problem:
In my experiment i have 2 loops.
GroupB to randomize between 4 treatments loops-not sequential- i want it to choose only 1 condition
I used the loops with condition file to randomize selected rows, it works perfectly in the builder
but when i finally synced to Pavlovia it resulted in an error * when importing condition: conditionB.xlsx
- TypeError: Cannot read property ‘length’ of undefined
i followed the Pavlovia: Randomization of selected rows results in error but then check the cribsheet and it says
"For nested loops the inner loop is referenced. It may not be possible to reference the outer loop.
Loop.finished=true No longer working "
so i am not sure how to fix this problem in my version 2021.1.1
Thank you!
What is random(1)*4 supposed to do? That doesn’t look like selected rows code I use.
To select just one row you need “n:n+1” where n=0 selects the first row. You might need to construct the text for this in a code component.
according to Flow — PsychoPy v2021.1 in order to to subset rows from conditions File
$random(4)*10 gives 4 indices from 0 to 9 (so selects 4 out of 10 conditions)
i tried with or without using the $ . it worked perfectly in the builder but i understand that it does not translate to JS so i need to write a code component.
should I add this in the beginning in the outer loop? i don’t have any routine in this loop since its mere purpose was to randomize the inner loops
i followed Pavlovia: Randomization of selected rows results in error - #2 by Marina_Chrisi
they replaced “$random(40)*159”
the code component they replaced the
if LoopName.thisN==49:
trials.finished=True
so i copied it
if GroupB.thisN==1:
trials.finished=True
but it the ignores it
Please take a look at my crib sheet.
.thisN also doesn’t work online
what eventually worked for me is removing the condition file.
adding a code component routine in the beginning of the external loop- in the each frame:
randNum = Math.floor(Math.random() * 4)
if (randNum == 0){
nRepsA = 1
nRepsB = 0
nRepsC = 0
nRepsD = 0
} else if (randNum == 1){
nRepsA = 0
nRepsB = 1
nRepsC = 0
nRepsD = 0
} else if (randNum == 2){
nRepsA = 0
nRepsB = 0
nRepsC = 1
nRepsD = 0
} else {
nRepsA = 0
nRepsB = 0
nRepsC = 0
nRepsD = 1
}
console.log({randNum})
probably could of written it in a shorter version
to be honest, i have no idea
when i put it in Begin Routine it completely ignored the code.
it makes no sense to me
Looking for logic here I think it’s possible that Begin Routine gets ignored if the routine has no duration. Adding a component with a duration of one frame should be sufficient.
However, if the routine has no duration then Each Frame should only run once anyway.
1 Like
thank you for making sense into it. the routine indeed has no duration and should only run once.