Howdy, Stranger!

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

Supported by

[solved] Coding correct responses with a form

edited February 2016 in OpenSesame

Hi there,

I have a form set up with four mouse button responses, which are being logged as 'a', 'b', 'c' and 'd' in the data file with yes/no as responses. I am using this for a cognitive task in which each question has a correct response. I want to to add some script so if 'a' codes as 'yes', it adds a '1' into a new variable, and 'b' as 'yes' would add a 2 into the same variable etc. Ideally I want an additional variable column with the correct answer for each question to be able to automatically code if the answer is correct for each participant.

Apologies if this has been asked before; I had a search around and couldn't find an answer.

Many thanks,
Alex

Comments

  • edited 1:34AM

    Hi Alex,

    So the idea is that participants can always respond yes or no, with either one of 4 buttons? And then you just want to be able to specify which button was pressed?

    Depending on whether you used the mouse item or an inline_script, the button is stored either in a variable named button, or a variable named response. With this variable you can do anything you want, like creating a new variable. If you have a logger item in your trial sequence, then a variable will automatically be logged (meaning there will be a column for this variable), as long as you "set" it, using exp.set('variable_name', value). The correct response is already automatically logged if you use the mouse item. Otherwise you have to "set" the correct response for each trial separately.

    Cheers,

    Josh

  • edited 1:34AM

    Hi,

    Thanks for the response. Not 100% sure if I explained clearly. I created a form using a form base and opensesame script, and have four button widgets on screen, which have named A to D as variables. Participants click one of the four options to indicate their answer, which is giving me 'yes' or 'no' in the data sheet for each variable. The 'response' column says N/A.

    Thanks,
    Alex

  • edited 1:34AM

    Hi Alex,

    I don't want to hijack but i think i understand what you want, i had the same issue. The response variable is indeed not automatically collecting responses from the form. You need to add an inline_script directly after your form that contains the following statements to recode the answer and check if the answer is correct:

    # define the variables (just as an example)
    var.Answer = 0
    var.Correct = 2
    var.CorAns = 0
    
    # recode into one variable
    if var.A == 'yes':
        var.Answer = 1
    elif var.B == 'yes':
        var.Answer = 2
    # etc. etc.
    
    # check if answer is correct
    if var.Correct == var.Answer:
        var.CorAns = True
    else: 
        var.CorAns = False
    

    I hope this helps

    Laurent

  • edited 1:34AM

    Hi Laurent,

    Yes, this is what I meant. Thank you.

    A couple of other questions you might be able to help with... I have it set up with a loop, with a variable for each of the image files and questions used in the form. In the output I get a response time for all of the questions in the loop. Is there a way I can record the response time for the form click on one of the four boxes, for each condition?

    I was also wondering if, using the method you explained above, I can link the correct answer to the conditions in the loop by adding an extra column with the correct answer? So the value of Var.Correct would change for each of the questions?

    Thanks,
    Alex

  • edited 1:34AM

    Is there a way I can record the response time for the form click on one of the four boxes, for each condition?

    I don't think there is a direct way to do this no. You could decide to create the form with an inline_script instead of the custom_form item and manually obtain the timestamps. This thread has it written down better than i could.

    I was also wondering if, using the method you explained above, I can link the correct >answer to the conditions in the loop by adding an extra column with the correct answer? >So the value of Var.Correct would change for each of the questions?

    Yes, if you add the variable var.Correct to your loop and insert the correct values it should update the variable for every trial run. Don't forget to remove var.Correct = 0 in the script above to avoid it being overwritten every trial.

    Good luck!

  • edited 1:34AM

    Thank you. I really appreciate the help! :)

Sign In or Register to comment.