Howdy, Stranger!

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

Supported by

[solved] Using form_multiple_choice: how to log answers of 8 questions in a row?

floflo
edited November 2015 in OpenSesame

Hi,

I am working on a short questionnaire using form_multiple_choice. I have 8 MC questions with four answer options each (of which only one is correct). I want them all to appear one after the other and then provide a feedback screen afterwards that indicates the score.

I have built a small test experiment with three questions. I don't quite understand how the responses on the form_multiple_choice need to be logged and how I indicate which of the options is correct. I have now put together this:

Do I need a logger after each form_multiple_choice or is that overkill? How else can I keep track of the responses to the questions? Any pointers would be greatly appreciated. :)

Thank you for your time and have a nice day!

  • Florian

Comments

  • edited 11:15AM

    Hi Florian,

    How about you use a loop? In this sense, in each iteration you run your form once with one of the questions, log the response (with a logger) and then proceed with the next iteration. Once, all the questions are answered, you can leave the loop and present the feedback. Depending on what the feedback is supposed to look like, you might have to add some extra book keeping in an inline_script (accessing current response and store them permanently in another variable).
    In the loop_table of the loop, you'll have to set the question and the answers as variables.

    Does this help you?

    Eduard

    Buy Me A Coffee

  • floflo
    edited November 2015

    Hi Eduard,

    thanks, that got me at least two steps further!

    I now have a loop with a couple of variables (question_text, answer_option_[1 through 4], and correct_response (indicating which of the options [1 through 4] is correct).

    So now I have this structure:
    EDIT: I just realized that the formatting of the code block below was completely messed up. Fixed it now.

    main_loop
        sequence
            form_multiple_choice
            inline_script
            logger
        feedback
    

    When I run the experiment, all questions are shown - yay!

    However, I don't understand how to log the responses and/or access them in the inline_script. According to this part in the documentation I should be able to access them using var.variable_name. In the form_multiple_choice, I indicate that the "response variable" is response. In the inline_script, however, neither print(response) nor print(var.response) seem to work (both give me the error that they are "not defined").

    What does seem to work is using print(self.get("response")) (as suggested in this part of the documentation). This prints the text of the answer option, though. Is there a way to get the index of the option?

    Thanks!

    • Florian
  • edited 11:15AM

    First of all, which OpenSesame are you using? Accessing variables via var.<varname> was only introduced in Opensesame 3.0. For all older versions, you'd have to do something like this:

    var = exp.get('varname')
    # do stuff with var
    exp.set('newvar', newvar)
    

    There are some ways how to retrieve the index. The most straightforward one is this, I think

    resp = self.get('response')
    if resp == exp.get('answer_option_1':
         respI = 1
    elif resp == exp.get('answer_option_2':
         respI = 2
    
    # etc.
    
    exp.set('respI',respI)
    

    I hope you get the idea.

    Eduard

    Buy Me A Coffee

  • floflo
    edited November 2015

    Hi Eduard,

    this seems to work really well! I have used the suggested if-elif-else structure to determine the ID/index. When I use exp.set('varname', index), the logger will write varname to the .csv file. Awesome! Thanks a lot for that!

    Now I am wondering how I can display the score on the feedback sketchpad at the end. If I compute the score in the same inline_script and set it using exp.set('score', score), it gets written to the .csv as well. So that's great because I have trial-by-trial information regarding the score. However, when I try to set the text on the sketchpad to "Your score is [score].", it will complain that I am trying to use a variable that does not exist.

    You said above:

    you might have to add some extra book keeping in an inline_script (accessing current response and store them permanently in another variable)

    How would I go about doing this?

    Thank you for your time, Eduard - I really appreciate it!

    • Florian

    P.S.: I am using OpenSesame 2.9.6 on Mac OS Yosemite.

  • edited 11:15AM

    How would I go about doing this?

    I don't think it matters for your case. So just briefly, when using a loop to repeat some action and save some outcome to a variable, you need to make sure that you can use the outcome of each iteration, before it is overwritten by the next iteration. You can use lists rather than simple variables for example, but there many ways to go. At any rate, it should not matter for you.

    YOur problem lies in the prepare-run structure of OpenSesame. That is, since your outcome variable is computed during the run phase, on the fly, so to speak, it doesn't exist yet, when all the items in the sequence are initialized (during prepare).

    If you want to present feedback only once in the end of a block of questions, you can move it outside the sequence and you should be set (maybe you also have to initialize your score variable somewhere before). If you need it updated on every trial it is a bit more complicated.

    Eduard

    Buy Me A Coffee

  • floflo
    edited November 2015

    Thanks for the quick response.

    This is the structure of my experiment at the moment:

    It says here that "All inline_script items share the same workspace. This means that variables that are created in one inline_script are available in another inline_script." That's why I tried to initialize the score variable in the inline_script init_score (it contains only one line: score = 0). In the inline_script inside my sequence I have this code:

    # Update the score
    score = score + cresp
    exp.set('score', score)
    

    (cresp is either 0 or 1, indicating a correct response.)

    The logger will write this to the file but I still can't access score in the feedback sketchpad.

    If you want to present feedback only once in the end of a block of questions, you can move it outside the sequence and you should be set (maybe you also have to initialize your score variable somewhere before).

    That's what I did but I am still getting the message that the variable doesn't exist. How would I initialize it before and where?

    This is the very last step I need to make this work. :) Thanks a lot!

    • Florian
  • edited 11:15AM

    Ah, I was afraid this will happen. You could try the feedback item. So, don't use an a regular sketchpad, but the a version of it which is dedicated to make feedback presentation easier.

    Alternatively, instead of a sketchpad use an inline_script and and put your feedback in the runphase.

    from openexp.canvas import canvas
    
    cv = canvas(exp)
    feedback = 'You have %s out of %s correct!'% score, total_no
    cv.text(feedback)
    cb.show()
    self.sleep(5000) # of via keyboard.get_key()
    

    Eduard

    Buy Me A Coffee

  • floflo
    edited 11:15AM

    Hi Eduard,

    using a feedback item with the same text on it (i.e., "Your score is [score].") works without any problems! Beautiful. Thanks a lot for your help!

    • Florian
Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games