Creating Variables dependent on other variables
Hello everyone
I am currently designing an eye-tracking experiment for emotion recognition with OpenSesame 3.1.9b1.
To collect the answers, I used the built-in form for multiple choice answers.
According to my what I read on here, there is no way to indicate the correct response in the forms, right?
And also, there is no easy way to let the 'form_response' give out numbers instead of the respective strings, right?
I am very new to programming, and just started learning python to accomplish what I want.
So I tried to define a new variable with an inline_script-item after the form and before the logger.
I managed to create the variable, and it also prints some values to the log-file.
I want the variable to print 1 if "correct_response" and "response" are the same (strings) and 0 if otherwise.
(The definition for the correct response was done in the loop table with the variable correct_response, in case you wondered.)
But:
While testing, it only prints a 0 to the file, with an occasional 1 now and then.
The 1, however, does not turn up when the answer was right, but seems to appear randomly, also with wrong answers.
So I suppose there is something wrong with my code, or the code cannot access the variables in the way I want it to...
The code I used is the following:
def emotion_recognized (): print self.get('emotion_recognized') emotion_recognized = () if var.get('response') == var.get('correct_response'): emotion_recognized = 1 else: emotion_recognized = 0 var.set('emotion_recognized', emotion_recognized)
I would be really happy if anyone could help me resolve this, somehow!
Have a good start into the new week.
Best wishes from Switzerland and thank you very much in advance
Tim
Comments
Nevermind.
When I put the code in the run, not the prepare window of the inline_script, it seems to work just fine now!
But another question came up:
How can I sum the values in the variable
emotion_recognized
to a variable calledsum_correct
?I get an iteration error when I try to do so. It would be great to just do the same procedure, the correct response Item of the feedback does...
Any help appreciated!
Thanks and best wishes
Tim
Hi Tim,
Initialize
sum_correct
somewhere in the beginning of your experiment (or your block). Then every time you want to update it you just addemotion_recognized
to it:sum_correct += emotion_recognized
. If you want to use them in thefeedback
item, you should usevar.sum_correct
instead.Good luck,
Eduard
Dear Eduard
Thank you so much for your answer!
If I put the
var.sum_correct += emotion_recognized
it simply gives the same values as inemotion_recognized
, not the sum of correct trials.I inserted the code in the Script right after the Multiple Choice Form that gives the value to
emotion_recognized
.The
sum_correct
is initialized at the beginning of the experiment (right after the welcome page).Where's my mistake?
Best wishes
Tim