Display text stimulus in random postions
Okay I was able to solve an issue from a previous post by following @Fab advice.
https://forum.cogsci.nl/discussion/8384/experiment-not-running-on-osweb#latest
I located the error and took it out. But now a condition of my experiment is missing. I want to randomise the location of the text stimulus (e.g., x=302, -302; y=174, -174) within the parameters of a rectangle box (i.e., x=352, -352; y=224, -224) so that participants aren't just focusing on the center of the screen and zoning-out distractor letters in a flanker task.
I understand that I may have to adapt the following post to my requirements
but I have no idea where to start and how to implement the edits suggested in this post and similar ones. Do I edit the script in the sketchpad? I understand that inline_script does not work through OSweb so I hope it's not that.
I'm unsure how to edit it to achieve what I want. I've tried doing stuff with the random and uniform function but keep running into errors. Anyways here is the basic script at the moment.
set duration 0 draw rect color="#3e3e3e" fill=1 h=448 penwidth=1 show_if=always w=704 x=-352 y=-224 z_index=2 draw textline center=1 color=white font_bold=no font_family=mono font_italic=no font_size=50 html=yes show_if=always text="[Stimulus]" x=0 y=0 z_index=0
Here is the trial loop if it is of any use:
If anyone could point me in the right direction it would be much appreciated!
Cheers,
Megan
Comments
Hi @meganb_ire,
If you want to randomize the x and y coordinates of an object on a sketchpad, you'll need two things:
(1) some coding
You'll need to program some code to generate random x and y values within certain ranges. This coding can be written in Python in an
inline_script
object or in Javascript using aninline_javascript
object (if you aim to run your task in a browser rather than within OS, you'll need to opt for Javascript*, as Python coding is not supported in OSWeb). Furthermore, the code will need to be placed under the "prepare" tab of the scripting object, because the coordinates of objects on sketchpads are prepared before the sequence is executed. Hence, if you insert the code under the "run" tab, the sketchpad would be set before the code is executed and the output of your code would be taking effect on the next trial. (Note that if you want to be able to manipulate the content of objects while the trial is running, you should use a feedback slide instead of a sketchpad).To generate a random value within a certain range is easy in Python, you can use the randint function: https://www.w3schools.com/python/ref_random_randint.asp
In Javascript, it's a little more difficult but can be done like this in an
inline_javascript
object:* Note that Javascript in experiments intended to ruin in OS should use the ECMA 5.1 syntax, while the ECMA 6 syntax can be used for experiments run through the browser (most recent browsers support the ECMA 6 syntax). See: https://osdoc.cogsci.nl/3.3/manual/javascript/about/
(2) editing the sketchpad's script
Once you have generated variables containing the random x and y coordinates, you'll need to feed these into the script corresponding to the text object you want to appear in random locations. A centered object has coordinates of 0,0, which s what you currently have:
Let's say that through code you created variables called rnd_x and rnd_y. The above script should then be modified to:
Good luck!
Fabrice.