Howdy, Stranger!

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

Supported by

[solved] correct variable is "undefined" and acc variable is "0"

edited June 2014 in OpenSesame

Hello,

I just created a new OpenSesame experiment which calls only four different JPEGs and has two correct response keys. I created a loop with a sequence for it so it can call every trial randomly. The order in the sequence is:
fixation dot, JPEG, keyboard response, logger, and tone. (The tone should only occur when the subject presses the incorrect key, so I have it set as "run if [correct]=0")

When I run the experiment, everything seems to run smoothly except for the fact that the tone isn't occurring. But then I pull up the CSV file to look at the data, and the [correct] variable is marked as "undefined" for every trial and the [accuracy] variable is marked as "0" for every trial. Because it's not collecting the [correct] variable, the tone cannot sound. It does record which response (key) you are making and which one is the correct response for the trial. It also seems to be collecting response time correctly.

I looked at the logger, and the source for the [correct] variable, the [acc] variable, and the [response_time] variable is the keyboard response.

I'm not really sure why it is saying the [correct] variable is "undefined" and [acc] is "0" every time.
If you could help us, that would be great. Thanks!

Comments

  • edited 6:45PM

    Hi,

    Could you make sure that there is one (and only one!) correct response listed in the keyboard_response item?

    If you require multiple responses to be correct, please use the following code in the Run phase of an inline_script placed directly after the keyboard_response:

    # check if the response is the same as correct response 1
    if self.get("response") == self.get("corresp1"):
        exp.set("correct", 1)
    # check if the response is the same as correct response 2
    elif self.get("response") == self.get("corresp2"):
        exp.set("correct", 1)
    # if the response is not one of the correct responses, set correct to 0
    else:
        exp.set("correct", 0)
    

    This inline_script assumes that you have defined the correct responses in two variables in your loop: corresp1 and corresp2.

    Good luck!

  • edited 6:45PM

    Thanks! That worked for correct, but the acc variable is still saying "0" every time. Is there any way to fix that too?

  • edited 6:45PM

    Yes, there is. This will require some manual bookkeeping, but we will rely on some variables OpenSesame creates and updates behind the screens:

    # check if the response is the same as correct response 1
    if self.get("response") == self.get("corresp1"):
        exp.set("correct", 1)
    # check if the response is the same as correct response 2
    elif self.get("response") == self.get("corresp2"):
        exp.set("correct", 1)
    # if the response is not one of the correct responses, set correct to 0
    else:
        exp.set("correct", 0)
    
    # increase the total amount of responses by one
    self.experiment.total_responses += 1
    # if the response was correct, increase the amount of correct responses by one
    if self.get("correct") == 1:
        self.experiment.total_correct += 1
    # calculate the accuracy
    self.experiment.acc = 100.0 * self.experiment.total_correct / self.experiment.total_responses
    # save the accuracy under the two variables OpenSesame saves it to
    exp.set("acc", self.experiment.acc)
    exp.set("accuracy", self.experiment.acc)
    

    Good luck!

  • edited 6:45PM

    It worked :) thanks for all your help, Edwin!

Sign In or Register to comment.