Howdy, Stranger!

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

Supported by

[solved] updating variable

edited March 2015 in OpenSesame

Hi all!

I'm having some troubles in programming an experiment. In particular I'm trying to update a variable after the subject's response.
I've declared my variables at the beginning of the experiment in an inline code:

exp.set('acc_id1', 0)
exp.set('acc_id2', 0)

After the subject's response I've inserted an inline code to update the variables:

err_corr = self.get('correct')
if self.get('id') == '1': # the id refers to different images, to keep track of the accuracy for each images independently
if err_corr == '1'
exp.set('acc_id1', self.get('acc_id1')+1)
else:
exp.set('acc_id1', self.get('acc_id1')+0)
else:
if err_corr == '1'
exp.set('acc_id2', self.get('acc_id2')+1)
else:
exp.set('acc_id2', self.get('acc_id2')+0)

The experiments works but when I look at the results the values of my variables are always 0, as I declared them at the beginning of the experiment.

I've also tried with:

err_corr = self.get('correct')
if self.get('id') == '1': # the id refers to different images, to keep track of the accuracy for each images indipendentely
if err_corr == '1'
acc_id1 = self.get('acc_id1')+1
else:
acc_id1 = self.get('acc_id1')+0
else:
if err_corr == '1'
acc_id2 = self.get('acc_id2')+1
else:
acc_id2 = self.get('acc_id2')+0

but the result doesn't change.
Any suggestions?

Thank you in advance!

Cheers,
Andrea

Comments

  • edited 7:28AM

    I'm sorry for the code format! I try again!

    Here it is the code I used to declared the variables:

    exp.set('acc_id1', 0)
    exp.set('acc_id2', 0)
    

    And this is the code I used to update the variables:

    err_corr = self.get('correct')
    if self.get('id') == '1':
        if err_corr == '1':
            exp.set('acc_id1', self.get('acc_id1')+1)
        else:
            exp.set('acc_id1', self.get('acc_id1')+0)
    else:
        if err_corr == '1':
            exp.set('acc_id2', self.get('acc_id2')+1)
        else: 
            exp.set('acc_id2', self.get('acc_id2')+0)
    

    I've also tried with:

    err_corr = self.get('correct')
    if self.get('id') == '1':
        if err_corr == '1':
            acc_id1 = self.get('acc_id1')+1
        else: 
            acc_id1 = self.get('acc_id1')+0
    else:
        if err_corr == '1':
            acc_id2 = self.get('acc_id2')+1
        else: 
            acc_id2 = self.get('acc_id2')+0
    

    but the result doesn't change....

  • edited 7:28AM

    Hi Andrea,

    The problem is simply that you're comparing an int with a str. For example, Python will evaluate this as False: 1 == '1'. So the solution would simply be to compare err_corr to an int, like so:

    if self.get('id') == 1:
    

    Does that make sense? For more information about how OpenSesame deals with variable types, see:

    Cheers!
    Sebastiaan

  • edited 7:28AM

    It absolutely makes sense!!
    Thank you so much!

    Andrea

Sign In or Register to comment.