Setting visibility of a question based off of another question
I'm trying to make question two appear only when the user enters an answer for question one, question three show appear only when an answer has been entered for question two etc. Here's what I have so far:
# define our questions as an array of objects form = { "next": 0, "questions": [ { "question": 1, "text": "1) Which two chemicals are discussed?", "var": "q1", "col": 0, "row": 1 }, { "question": 2, "text": "2) How do you think these gases should be stored?", "var": "q2", "col": 0, "row": 3 }, { "question": 3, "text": "3) Why would it be dangerous to keep these chemicals in your fridge?", "var": "q3", "col": 0, "row": 5 }, { "question": 4, "text": "4) At what temperature does some combustion occur?", "var": "q4", "col": 0, "row": 7 }, { "question": 5, "text": "5) What does the success of using this mixture depend upon?", "var": "q5", "col": 0, "row": 9 } ] } def form_validator(): return var.q1 != u'' and var.q2 != u'' and var.q3 != u'' and var.q4 != u'' and var.q5 != u'' def show_next_question(): print("showing next question") next = form["next"] if next < 5: next += 1 q = form["questions"][next] paint(q) return True def paint(q): if q: label = Label(u''+q["text"], center=False) input_fld = TextInput(var=u''+q["var"]) my_form.set_widget(label, (q["col"], q["row"]), colspan=4) my_form.set_widget(input_fld, (q["col"] + 4, q["row"]), colspan=4, rowspan=2) # Form my_form = Form( validator=form_validator, cols=8, rows=13, spacing=25, margins=(50, 50, 50, 50)) title = Label(u'Gases ', center=True) my_form.set_widget(title, (0, 0), colspan=8) # Create the first question paint(form["questions"][0]) # button_ok = Button(u'Next') button_next = Button(u'Next') my_form.set_widget(button_next, (2, 11), colspan=4, rowspan=2) my_form._exec() # Log answers log.write_vars()
But I don't know how to detect an answer to question one without the form crashing; I've tried adding the show_next_question function to the input as a key_filter and looked into setting up the questions as normal but changing the label & input to the background colour to give the effect of not being there.
What am I doing wrong here?
Thanks
Comments
Hi @Katana24 ,
you have posted this question to the osweb forum. Is your intention to run this experiment online, or does your question only involve running the experiment in OpenSesame? If so, it is better to repost this question in the appropriate OpenSesame group.
Currently, form items and inline script items with Python code are not supported by osweb, so the code you posted above will not be able to run online.
Thanks for getting back Daniel. The original intention was to run it via the web but, thanks to Sebastiaan I realized that the features I was looking to use can't be used on the web so I've settled for running it via its own window.