Howdy, Stranger!

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

Supported by

[solved] Using an answer as a variable in a next question

edited April 2013 in OpenSesame

Hi all!

Me and my research-partner have a problem and we seem to have no solution for this:

We ask our participants in question 1 if they could fill in the three types of food they crave for at the moment. (So we want three empty lines where they could fill in there options, and we don't know how to do that)

After that, we want to ask them in question 2, which one of the three food types they favoure the most. So that all three options will be displayed, and they kan click on the most favourable. To do this, we need to use all three the answers at question 1 to form question 2. Obviously, that is our main problem.

After this we will need the three answers in some more questions, but I will nog bore you with that.

Concluding: We want the answers at question 1 given in a form_text_input, to be saved as a variable, to use it in the next form_text_input. This should be easy to achieve through an inline_script, we just don't know how.

Thanks so much for responding!

Comments

  • edited April 2013

    Hi,

    The problem is that all forms that are part of the same sequence are prepared at the same time, so they cannot depend on each other. The solution is simply to arrange the forms into different sequences, like so:

    image

    form_text_input and form_multiple_choice are now in different sequences, and therefore no longer prepared together. They will still be executed sequentially, as long as sequence1 and sequence2 are in turn part of a larger sequence.

    One other thing that you probably want to do is process what participants enter into form_text_input. For example, this script (placed immediately after form_text_input) will take their text input and split it into separate responses ('Apple', 'Chocolate', etc.). Each response is set to a different variable, which can then be used as response options in the form_multiple_choice item.

    # Get the response and split it by comma's:
    # Apple,Chocolate,Ice -> ['Apple', 'Chocolate', 'Ice']
    # This assumes that the response variable in form_text_input is `response`.
    l = self.get('response').split(',')
    # If a different number of responses have been entered, run the form again, and
    # process the response again as well.
    while len(l) != 3:
        exp.items['form_text_input'].prepare()
        exp.items['form_text_input'].run()
        l = self.get('response').split(',')
    # Set all three responses. These can now be used as response options
    # in form_multiple_choice.
    exp.set('response1', l[0])
    exp.set('response2', l[1])
    exp.set('response3', l[2])
    

    Does that answer your question?

    Cheers!
    Sebastiaan

  • edited 8:02PM

    Thank you very much for your quick response.
    But sadly it doesn't solve the problem..
    When I insert the separate sequences, one with the form_text_input and the inline-script and one with the form_multiple_choice, it simply keeps running the form_text_input regardless of the input (whether it's one or three words). The form_multiple_choiche never shows, neither does the rest of the experiment.

    Also, I'm completly new with inline_scripts, so should I put the code in the prepare or in the run phase? (I tried both, didn't make a difference)

    I also wondered if it was possible to use an input as a variable in a form_text_input or a slider. We want to aks the participants how much craving they experience (on a slider) for the three types of foods. But to do so we need to intergrate the given responses in the earlier form_text_input into the questions on the slider form..

    Thank you for your help!

  • edited 8:02PM

    When I insert the separate sequences, one with the form_text_input and the inline-script and one with the form_multiple_choice, it simply keeps running the form_text_input regardless of the input (whether it's one or three words)

    The script runs the form again if it cannot split the string into exactly 3 comma-separated words. My guess is that you are not using commas to separate the words, is that correct? You can specify your own separator in the script (it can be anything):

    l = self.get('response').split(',') # Splits by comma
    

    Also, I'm completly new with inline_scripts, so should I put the code in the prepare or in the run phase? (I tried both, didn't make a difference)

    Right, this code should be in the run phase, because it relies on the response that is collected during the execution of the sequence. The prepare phase contains things that can be done 'in advance', so to say.

    I also wondered if it was possible to use an input as a variable in a form_text_input or a slider. We want to aks the participants how much craving they experience (on a slider) for the three types of foods. But to do so we need to intergrate the given responses in the earlier form_text_input into the questions on the slider form.

    In the case of a form_text_input, you can use the text keyword, as described here:

    If you click on the 'edit script' button in the form_text_input tab, you will see (among other things) this line, which corresponds to the text_input widget.

    widget 0 2 1 1 text_input focus="yes" return_accepts="yes" var="[form_var]"
    

    Let's say that the response that you want to use to give the text_input content is called my_response_var. You can then change the line as follows:

    widget 0 2 1 1 text_input focus="yes" return_accepts="yes" var="[form_var]" text="[my_response_var]"
    

    Regarding the slider, you probably refer to the slider plug-in from the questionnaire plug-in pack, right? The slider is linked to the mouse position, so it doesn't really have an initial value like a text_input. What did you have in mind exactly?

    Cheers,
    Sebastiaan

  • edited 8:02PM

    Thank you very much! It's finally working :)
    Only thing is that when the three questions are answered, the experiment starts over with the first question instead of continuing with the rest of the experiment?

    Regarding the slider plug-in I actually meant that I wanted to use one of the response variables (response1, response2 or response3) in the QUESTION of the slider. But when I just type [response1] in the text field I get the following error: variable 'response1' is not set in item 'slider'. The slider is in the same main sequence as the two other questions, but all three of them are in a seperate subsequence as you instructed.

  • edited April 2013

    @Sebastiaan: she does mean the slider plugin, which has been improved to meet the requests made by some of my colleagues. It's on my github.

    @ Julia: the problem is in the fact that the slider prepares the presentation of the question up front. So the question is drawn before your form is run, therefore the response isn't available yet.

    An ugly workaround could be to put the slider in an extra loop, as such:

    Example experiment code:

    # Generated by OpenSesame 0.27.1 (Frisky Freud)
    # Tue Apr 02 18:55:39 2013 (nt)
    # 
    
    set foreground "white"
    set subject_parity "even"
    set font_size "18"
    set description "Default description"
    set title "New experiment"
    set font_bold "no"
    set sampler_backend "legacy"
    set coordinates "relative"
    set height "768"
    set mouse_backend "legacy"
    set width "1024"
    set compensation "0"
    set font_family "mono"
    set keyboard_backend "legacy"
    set background "black"
    set subject_nr "0"
    set canvas_backend "legacy"
    set start "experiment"
    set synth_backend "legacy"
    set font_italic "no"
    
    define sequence sequence
        run slider "always"
    
    define sketchpad welcome
        set duration "0"
        set start_response_interval "no"
        set description "Displays stimuli"
        draw textline 0 0 "OpenSesame 0.27 'Frisky Freud'" center=1 color=white font_family="serif" font_size=32 font_italic=no font_bold=no show_if="always"
    
    define keyboard_response keyboard_response
    
    define slider slider
        set bg_colour "black"
        set fg_colour "white"
        set sf_colour "red"
        set leftlabel "Disagree"
        set show_img "no"
        set question "[response]"
        set slider_h "10"
        set slider_w "800"
        set rightlabel "Agree"
        set txt_colour "white"
        set accept_text "Click to accept"
        set description "Presents a question and slider"
    
    define sequence experiment
        run welcome "always"
        run keyboard_response "always"
        run loop "always"
    
    define loop loop
        set item "sequence"
        run sequence
    
  • edited 8:02PM

    Only thing is that when the three questions are answered, the experiment starts over with the first question instead of continuing with the rest of the experiment?

    The example that I posted does not restart by itself, so this must be a consequence of your experiment structure. Perhaps you could post a screenshot of your overview area?

    Regarding the slider plug-in I actually meant that I wanted to use one of the response variables (response1, response2 or response3) in the QUESTION of the slider. But when I just type [response1] in the text field I get the following error: variable 'response1' is not set in item 'slider'.

    As Edwin points out, if you have added the slider to a different sequence and the variable that you are using ([response1]) is available, than using the variable in the question text should work. But again, a screenshot of your overview area will probably make the problem clear.

    Cheers!

    PS. I noticed a mistake in the code I posted previously, where second split used chr(10) (= newline) instead of ,. But I guess you already spotted this one yourself!

  • edited April 2013

    There was another (unrelated) error in the script. It now works.

  • edited 8:02PM

    Everything worked perfect, until I added some loggers.
    Now, out of nowhere, the inline script won't work anymore..
    I get the following error:

    Error: Inline script error
    In: inline_script (run phase)
    Line: 4

    Python traceback:
    AttributeError: 'int' object has no attribute 'split'

    We didn't change anything and it worked fine until I added some loggers...
    Since Edwin is not avaible today, I was wondering if you, Sebastian, could help us.

  • edited 8:02PM

    The problem is solved, thanks to the automatic back up function :)

  • edited 8:02PM

    Great! Marking this one as solved.

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