Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Creating Variables dependent on other variables

edited September 2017 in OpenSesame

Hello everyone :smile:

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 called sum_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 add emotion_recognized to it: sum_correct += emotion_recognized. If you want to use them in the feedback item, you should use var.sum_correct instead.

    Good luck,

    Eduard

  • edited September 2017

    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 in emotion_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

Sign In or Register to comment.