PennController for IBEX › Forums › Support › Conditionals/display logic
- This topic has 7 replies, 3 voices, and was last updated 2 years, 4 months ago by
laiamt.
-
AuthorPosts
-
September 27, 2020 at 11:46 am #6165
August
ParticipantHi Jeremy:
I wish to display different tasks based on participants’ answers to their answers to the previous question. For instance, for people who answered ‘No’ to the question, they can continue to the next trial, but for people whose answer is ‘No’, I want to have them to do a follow-up task before going to the next trial. Is that possible?
Thanks so much!
Best wishes,
AugustSeptember 28, 2020 at 10:18 am #6167Jeremy
KeymasterHi August,
Yes, it is possible. You’ll have to use a global Var element to store and retrieve the participant’s answer to the previous trial. Then depending on its value you either run the full next trial, or you skip over it. Here’s a basic example:
newTrial( newText("How many inches in a foot?").print() , newScale("answer", '10','11','12','13','14').button().print().wait() , newVar("inches").global().set(getScale("answer")) ) newTrial( getVar("inches").test.is(12).failure( newText("How many centimeters in a meter?").print() , newScale("answer", '10','100','1000').button().print().wait() .test.selected(100).success( newText("Good job!").print() ) .failure( newText("Oh well, better luck next time").print() ) , newButton("Next").print().wait() ) ) newTrial( newText("This test is over!").print() , newButton().wait() )
Let me know if you have questions
Best,
JeremySeptember 30, 2020 at 11:58 pm #6178August
ParticipantThanks so much!! This is super helpful!
October 25, 2022 at 9:46 am #9614laiamt
ParticipantHi Jeremy,
I have a similar question to the one above. In my case, I have a checkbox scale. If participants select (at least), the third option, they should proceed to the rest of the experiment. If they don’t, they should only see the last screen.In my attempt, however, the experiment ends after the participants select any of the options of the scale.
I include the code and the demonstration link below.Any help will be greatly appreciated.
Best,
LaiaSequence( "pretest", "exp", SendResults(), "end") newTrial("pretest", newScale("input_tag1", "eh", "no", "oi", "fa") .checkbox().log().vertical().print(), newVar("tag1").global().set(getScale("input_tag1")), newButton("go", "Endavant") .print() .wait() ) newTrial("exp", getVar("tag1").test.is(oi).success( newText("instrus1", "You selected 'oi'!.") .print(), newButton("go", "Endavant") .print() .wait() ) ) newTrial("end", newText("end1", "We are done") .print(), newButton().wait() )
Demonstration link: https://farm.pcibex.net/r/IvVKNg/
October 25, 2022 at 5:39 pm #9620Jeremy
KeymasterHi Laia,
Your first trial (“pretest”) shows a Scale element, immediately sets the Var element “tag1” to the currently selected value on the scale (ie. no value, since the participant hasn’t had time to make a choice yet) then prints the “go” button and wait for a click before moving on to the next trial
You second trial (“exp”) actually contains a fatal error, so it won’t be run, but if it were, it would check that the value of that Var element corresponds to the value of the variable
oi
, which is not only undefined (as far as I can tell) but most importantly not declared: the script does not know whatoi
refers to and crashes at that point, never creating the second trial nor executing any of the code that comes after that (ie. it doesn’t create the “end” trial either)So you’ll want to switch the order of the last two lines of your first trial and add double quotes around
oi
in the second trial:newTrial("pretest", newScale("input_tag1", "eh", "no", "oi", "fa") .checkbox().log().vertical().print(), newButton("go", "Endavant") .print() .wait(), newVar("tag1").global().set(getScale("input_tag1")) ) newTrial("exp", getVar("tag1").test.is("oi").success( newText("instrus1", "You selected 'oi'!.") .print(), newButton("go", "Endavant") .print() .wait() ) )
If by “selecting at least oi” you mean selecting “oi” or “fa”, you can add a disjunct to your test:
getVar("tag1").test.is("oi").or( getVar("tag1").test.is("fa") ).success(
Jeremy
October 26, 2022 at 3:45 am #9621laiamt
ParticipantHi Jeremy,
Thanks, that’s very helpful.By ‘selecting at least oi’, I mean that if they select ‘oi’, they should proceed with the experiment, regardless of whether they also chose other options. So they should proceed, if they select only ‘oi’, if they select ‘oi’ and ‘fa’, if they select ‘oi, ‘fa’, ‘no’, etc…. Is there any way to do this?
Thanks again,
Laia
October 26, 2022 at 11:04 am #9623Jeremy
KeymasterHi Laia,
This line
newVar("tag1").global().set(getScale("input_tag1"))
will set the Var element to the last selected value, so you won’t exactly get what you want indeed: if the participant checks “oi” and later on also checks “fa”, then the Var element’s value will be “fa” and you won’t detect that “oi” is still checkedBecause the Scale element only detects the most recent selection, you’ll need to use a workaround:
newTrial("pretest", newScale("input_tag1", "eh", "no", "oi", "fa") .checkbox().log().vertical().print(), newButton("go", "Endavant").print().wait(), newVar("tag1").global().set( ()=>document.querySelector("input[value='oi']").checked ) ) newTrial("exp", getVar("tag1").test.is(true).success( newText("instrus1", "You selected 'oi'!.") .print(), newButton("go", "Endavant") .print() .wait() ) )
Jeremy
October 28, 2022 at 5:56 am #9637laiamt
ParticipantThanks a lot!
-
AuthorPosts
- You must be logged in to reply to this topic.