Howdy, Stranger!

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

Supported by

Creation of new variables and storing in logger using custom form with loop

edited June 2017 in OpenSesame

Hello,

Using OpenSesame 3.1.6

I have a form_base that contains image-buttons whose content is specified via a loop that calls a sequence (containing a single form/test to run).

The loop contains a list of words to be translated ([word_to_translate]), and three "guesses"/words given to the participant: [guess1], [guess2], [guess3]. These options are presented to the participant as image-buttons:

widget 0 0 1 1 label text="[word_to_translate]"
widget 0 1 1 1 image_button path="[guess1].png" var="[word_to_translate]\_[guess1]"
widget 0 2 1 1 image_button path="[guess2].png" var="[word_to_translate]\_[guess2]"
widget 0 3 1 1 image_button path="[guess3].png" var="[word_to_translate]\_[guess3]"

The correct answer [correct_response] is also specified in the loop's table.

I have the "Log all variables" enabled in the logger, and I am seeing the following info correctly registered:

[word_to_translate]_[guess1] -> Yes/No
[word_to_translate]_[guess2] -> Yes/No
[word_to_translate]_[guess3] -> Yes/No
time_[word_to_translate]
etc

What I also want to record in the logger is the following info:

(a) Whether the participant answered correctly for any given [word_to_translate], i.e. effectively something like:
was_correct_answer_given_for_[word_to_translate] --> Yes/No

(b) The "response time", defined (I guess?) as
response_time_[word_to_translate] = time_[word_to_translate] - time_["previous"_word_to_translate]

But I don't know how to do either of them.

Could you please let me know if this is feasible?

With many thanks,

--Christos

Comments

  • Hi Cristos,

    In this case, I think you're better off using a simple inline_script. Below you see an example of how that works, with the difference that I used a button widget instead of an image_button. But the idea is the same. Does that clear things up?

    Cheers,
    Sebastiaan

    from libopensesame import widgets
    
    # These variables are probably defined in a loop table
    var.word_to_translate = u'pour'
    var.guess1 = u'to'
    var.guess2 = u'for'
    var.guess3 = u'against'
    var.correct_response = u'for'
    
    # Create a form
    form = widgets.form(exp, cols=[1], rows=[1,1,1,1])
    form.set_widget(widgets.label(form, text=var.word_to_translate), (0,0) )
    form.set_widget(widgets.button(form, text=var.guess1), (0,1) )
    form.set_widget(widgets.button(form, text=var.guess2), (0,2) )
    form.set_widget(widgets.button(form, text=var.guess3), (0,3) )
    
    # Execute the form and see how long it took. Also see if the return value of the
    # form matches the correct response. In the case of an image_button, the return
    # value wil correspond to the `path`.
    start_time = clock.time()
    response = form._exec()
    response_time = clock.time() - start_time
    correct = response == var.correct_response
    
    # Add the response to the response history!
    responses.add(response=response, correct=correct, response_time=response_time)
    
  • Many thanks for the detailed response, Sebastiaan. I can see that with the inline python one has much more flexibility.

    I still need some help with adding some variables to the response history, though. As it stands, only the response, correct and response_time from the last entry in the loop table are saved (because they are overwritten every time the sequence is called). Can I add a "_word_to_translate" suffix to these variables somehow? Not sure how to do that.

    (my logger claims it logs all variables)

    --Christos

  • You can specify an item as keyword. If you do that, OpenSesame will also register the responses with a _[item] suffix, just like for a keyboard_response.

    responses.add(
        response=response,
        correct=correct,
        response_time=response_time,
        item='some_unique_identifier')
    

    See also:

  • Thank you very much Sebastiaan! This seems to do what I need.

    Best, C.

Sign In or Register to comment.