[solved] Using an answer as a variable in a next question
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
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:
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.
Does that answer your question?
Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
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!
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):
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.
In the case of a form_text_input, you can use the
textkeyword, 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_inputwidget.Let's say that the response that you want to use to give the
text_inputcontent is calledmy_response_var. You can then change the line as follows: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
Check out SigmundAI.eu for our OpenSesame AI assistant!
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.
@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 sequenceThe 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?
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!Check out SigmundAI.eu for our OpenSesame AI assistant!
There was another (unrelated) error in the script. It now works.
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.
The problem is solved, thanks to the automatic back up function
Great! Marking this one as solved.