[solved] Rnd Positions - Inline Script - Newbie
Hello everybody,
I am new to OpenSesame and trying to create my first experiment with it, but I have some problems:
My experiment is a calculation task, where subjects have to calculate a problem (e.g. 6x7) and on the next screen choose an answer with the mouse out of seven choices presented in an ellipse. This is what the general program structure looks like:
Within all the different loops for each trial I have the following variables: Operand 1, Operand 2, Choice 1, ..., Choice 7, x-Coordinate 1, y-Coordinate 1, ..., x-Coordinate 7, y-Coordinate 7 (op1, op2, choice1, ..., choice7, x1, y1, ..., x7, y7)
My goal is simple: I just want to randomly set the positions for each trial. Thats why after showing the calculation problem with the two operands (problem_symbolic) I inserted the following inline script (randomly_set_positions_symbolic):
Prepare phase: #empty
Run phase:
import random
coords = [[0, -220],[248,-160],[340,80],[128,222],[-128,222],[-340,80],[-248,-160]]
random.shuffle(coords)
for i in range(1,8):
xvar = "x" + str(i)
yvar = "y" + str(i)
c = coords.pop()
x = c.pop(0)
y = c.pop()
exp.set(xvar, x)
exp.set(yvar, y)
If I try to run it, all answer choices end up in the centre of the screen, so the preassigned 0 0 coordinates are not overwritten by the script.
This is what the answer_symbolic sketchpad looks like:
set duration "0"
set description "Displays stimuli"
set start_response_interval "yes"
draw circle 0 -220 250 fill=0 penwidth=3 color=white show_if="always"
draw circle 128 222 250 fill=0 penwidth=3 color=white show_if="always"
draw circle -248 -160 250 fill=0 penwidth=3 color=white show_if="always"
draw circle 248 -160 250 fill=0 penwidth=3 color=white show_if="always"
draw circle -128 222 250 fill=0 penwidth=3 color=white show_if="always"
draw circle -340 80 250 fill=0 penwidth=3 color=white show_if="always"
draw circle 340 80 250 fill=0 penwidth=3 color=white show_if="always"
draw textline [x1] [y1] "[choice1]" center=1 color=white font_family="mono" font_size=40 font_italic=no font_bold=no show_if="always" html="yes"
draw textline [x2] [y2] "[choice2]" center=1 color=white font_family="mono" font_size=40 font_italic=no font_bold=no show_if="always" html="yes"
draw textline [x3] [y3] "[choice3]" center=1 color=white font_family="mono" font_size=40 font_italic=no font_bold=no show_if="always" html="yes"
draw textline [x4] [y4] "[choice4]" center=1 color=white font_family="mono" font_size=40 font_italic=no font_bold=no show_if="always" html="yes"
draw textline [x5] [y5] "[choice5]" center=1 color=white font_family="mono" font_size=40 font_italic=no font_bold=no show_if="always" html="yes"
draw textline [x6] [y6] "[choice6]" center=1 color=white font_family="mono" font_size=40 font_italic=no font_bold=no show_if="always" html="yes"
draw textline [x7] [y7] "[choice7]" center=1 color=white font_family="mono" font_size=40 font_italic=no font_bold=no show_if="always" html="yes"
Can anybody who has experience with OpenSesame please help me with this? It should not be a difficult task I guess
Thank you very much in advance for any idea!
Cheers,
Hannes
Comments
Hi Hannes,
You've actually done a really good job, there's simply a single detail you might have overlooked: a sketchpad is constructed in the Prepare Phase. Since your
inline_script
is run only in the Run Phase the variables used in your sketchpad (x1,...,x7, and y1,...,y7) are not properly defined yet. That is: the variables are defined, but they still have the preassigned values that you mention.The solution is very simple: move your code from the Run Phase to the Prepare Phase and you should be good to go!
EDIT: Thought this might be useful. If you want to know more about the difference between the two phases, and why OpenSesame uses an approach in which your stimuli are pre-created before they are run, please see this page on the Documentation website.
Good luck!
Edwin
Hey Edwin,
thank you soooo much for your quick help, it works perfect now!
And also thanks a lot for the link!! I guessed it would be some stupid mistake on my side since I don't know OpenSesame well yet.
I really appreciate your fast support, getting started in a new environment can be frustrating in the beginning when encountering problems like this.
Have a nice day,
cheers
Hannes
Hi Hannes,
That's excellent, very good to hear that you've got things running and that you're happy with us! I'll mark the issue as solved, and I wish you the best of luck with your experiment.
Cheers!
Edwin