Variable ISI - javascript equivalent for python random.randint()?
Hi,
I would usually have a random (constrained) fixation screen duration between stimuli (ISI).
In OpenSesame this works (e.g. for fixation duration approx 1000ms, varied between 750 and 1250ms):
import random
var.fix_duration = random.randint(750, 1250)
Does anyone have examples of how to convert this to OSWeb Inline in order to use it in an online experiment?
Thanks,
Carolyn
Comments
Hi @carolyn.
In javascript most of these functions are located in the
Mathlibrary. the functionMath.random()returns a value between 0 and 1, so you could translate your statement as such:I hope this helps.
Hi Daniel,
Thank you for the quick response, that works!
Cheers,
Carolyn
Hi,
I have a simlar query. I'm converting an experiment to work on OSWEB. I have a variable ISI that ranges between 500-1500 with steps of 100ms.
The current script is as follows.
I am not a coder and get buy by finding other peoples codes and modifying where necessary. Any help would be gratefully received.
Best wishes
Deiniol
Hi @Skilli
The stepping makes it more difficult. Unfortunately javascript doesn't have a
random.choicelike function, so you will have to do something like:That should do the trick.
Thanks @Daniel
This makes alot of sense to me along with the text above. I had to declare the variable ITI at the start of the experiment (see image)
However, it does not work. I get an invalid duration error message (see image)
Here is how the code looks in the experiemnt.
Hi @Skilli
You need to place this code in the prepare phase while you put it in the run phase.
Good man! Thanks you @Daniel that worked. Just one question, why does code have to go in the prepare phase and not the run phase. From what I understood, declaring variables go in the prepare phase and running code goes in run, as it runs.
Please excuse stupid questions, I'm trying to learn.
Thanks again
Deiniol
Hi @Skilli,
The long explanation you can find here: https://osdoc.cogsci.nl/3.3/manual/prepare-run/
The short explanation: everything in the prepare phase section of script items is executed before the trial starts (i.e. the first display is shown). This is to make sure that potential time consuming calculations do not mess up the timings of the displays when they are shown. So generally, all code that is resource intensive and may take some time to execute should be placed in the prepare phase. Because all other items beside inline scripts also have this prepare phase in which they set themselves up to run, they need to have information about duration etc. already in this phase, and therefore you needed to define the ITI in this phase too.
Code in the run phase is executed during a trial run. Generally you only place code here that involves the actual presentation of the displays (e.g. `canvas.show()`) or code that is dependent on the response of the participant.
I hope this helps! (and thanks for the caffeine shot ;) )
Thanks @Daniel. Does that means inline script using the prepare phase can go anywhere in the trial sequence?
Basically yes. Within a sequence, all prepare phases are executed before all the run phases. So as long as each of the prepare phases does not rely on stuff happening in future prepare phases or any of the run phases, it can go anywhere in the sequence.
Of course there are some obvious mistakes to make (e.g. using the user response in a prepare phase), but these are usually quickly found.
Good luck,
Eduard