Block randomisation with inline JavaScript
Hi !
I am trying to randomise the execution order of blocks within a sequence. This two posts show similar solutions, working perfectly, but using an inline Python script:
https://forum.cogsci.nl/discussion/521/open-block-randomisation-with-inline-script-at-the-run-phase
However I will run my experiment online, and so I must use inline Javascript (and not Python). Here are the problems associated to both solutions given above:
- In the first solution given above, I have not found a way to write the prepare/run strategy in Javascript. Is there a solution for that ?
- In the second solution, I have not found a way to write a Javascript-style conditional statement for the "run-if" statement. Is there also a solution for that ?
Thank you very much !
Comments
Hi @bbkm ,
That code is certainly possible to rewrite in Javascript if you know that language, but you want to consider a simpler solution that requires no programming at all.
It may be that you want to shuffle the conditions following certain rules, in which case some programming will be needed (hopefully someone with knowledge of Javascript can help you with this). But if what you just want is to execute blocks in a random order (that what I understand from your post), you could simply use a nested design and take advantage of the "Run if" option of sequences....
First, create a loop of blocks with some variable that identifies each block separately:
Next, create a block sequence in which you insert a loop for each block, and use "Run if" to condition the execution of one of these blocks to the value of "BlockID":
Et voilà! Bob's your uncle! Now the task runs blocks A, B, C and D in a random order.
You can download this basic example here:
Note that in this example, I've assumed that in each block you want to run the same sort of sequence, just change the stimuli, so I pasted a linked copy of the same sequence (Trial_sequence) in each block. However, if you wanted something entirely different to happen in each block, you could of course create a unique sequence for each block.
This method uses no programming code at all and will run fine in your browser. It's is JATOS compatible.
Hope this helps.
Fabrice.
Thank you very much Fabrice! This saved me a lot of time and it worked perfectly :)!
You're welcome, @bbkm . Glad it helped. Coding is great but sometimes simpler solutions do the trick just fine.