Howdy, Stranger!

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

Supported by

[solved] OpenSesame: Use lists made in an inline script as 'variabeles'

edited March 2016 in OpenSesame

Hello all,

I've a new question. I've made a inline script that generates equations combined with an answer and a type and saves it as dictionaries in a list (because in this way each equation has been connected to the right answer and type). In a block loop, you are able to make variables and give each variable different values. I would like to use my script to generate three variables (equation, answer and type). So that, each round, one equation will be used out of the list. How do I do this? How do I connect the list of equations I generate with the inline script to the block-loop? Or is it not necessary to add variables to the block-loop and do I have to connect it to an sketchpad to directly show an aquation to the participant? And how do I keep the answer and type connected to the equation?

I hope my question is understandable. If my description is to faque, please let me know!

Comments

  • edited March 2016

    Hi Merel,

    One solution that comes to mind is to change your dictionary into a list of smaller lists.
    In the smaller lists, the first element is the question, the second one is the correct response, and the third one is the type.

    For example:

    Define the entire list at the beginning of your experiment:

    lEq = [
        ["2 x 2 = ", "4", "multiplication"],
        ["2 + 3 = ", "5", "addition"],
        ["2 - 2 = ", "0", "subtraction"]
        ]
    
    # If you want, you could randomize the list. (This won' affect
    # the content of the smaller lists):
    import random
    random.shuffle(lEq)
    

    Append aninline_script item to the beginning of the trial sequence, and place something like the following in the Prepare tab:

    # Pop one equation from the list. This is without replacement:
    var.equation = lEq.pop()
    
    # We now have one small list, where the first item is the
    # question, the second one the correct response,
    # and the last one the type of equation.
    
    # (We tell OpenSesame what the correct answer is by setting the
    # built-in variable 'correct_response')
    
    var.question, var.correct_response, var._type = var.equation
    

    Now you can use the variables question, correct_response and equation as if they were defined in the block_loop. For example:

    image

    The three variables are also logged, so you can keep track of all three of them.

    I hope this helps!

    Cheers,

    Lotje

    Thanked by 1booradley
  • edited March 2016

    Hi Lotje,

    Thanks for your response! I still have a question:

    In the inline script you made, one equation will be shown to the participant, but how do you loop through the list of equations to show them all, one by one, to the participant?
    Or is that solved by using 'pop'?

  • edited 1:52AM

    Hi Merel,

    I thought the idea was to show the participant one equation per trial:

    • show equation
    • collect the response
    • log all variables from the current trial

    etc.

    If this is indeed what you want, I think the above method should work. I just forgot to mention that you have to set the number of cycles in the block_loop to the total number of equations.

    I uploaded an example here:
    http://pastebin.com/9Jumk5Cj

    (download and save with the extension .osexp)

    If this is not what you meant, please let me know!

    Cheers,

    Lotje

  • edited 1:52AM

    Also, I get an error that lEq is not defined .. :(

  • edited 1:52AM

    Thanks! I will look at your example first!

  • edited March 2016

    Hi Lotje,

    Thanks a lot for your help! My experiment is working now! I changed your example a little by using the list of dictionaries directly instead of making it a list of lists.

    # Pop one dictionairy from the list of dictionairies. This is without replacement:
    var.equation = final_equations.pop()
    
    # Connect items dictionary to variables
    var.question = var.equation["equation"] 
    var.correct_response = var.equation["answer"]
    var._type = var.equation["type"]
    

    you're example was very useful, thanks!

    Cheers,

    Merel

Sign In or Register to comment.