Reply To: Feedback based on slider scale selection

PennController for IBEX Forums Support Feedback based on slider scale selection Reply To: Feedback based on slider scale selection

#10396
Jeremy
Keymaster

Hello,

This is because, in the absence of a selection, the choices array is empty, so the code in the Function element will crash when trying to reference the value of “the last choice” (presupposition failure: there is no choice to start with). What you can do to address the crash is return a dummy array in the absence of choices

Regarding the specific feedback messages, you can handle them in two separate tests in wait, just like you tried to do: one that tests whether the Scale was interacted with, and one that checks the value on the Scale. The former will fail in the absence of a selection, so the latter just won’t matter (but won’t crash because of the dummy array; and we’ll make it succeed so as to not print its own feedback message in the absence of a choice)

Now, because you want to provide different feedback depending on which test fails, neither should be the main test in the wait command and to which ands are appended, otherwise you’ll get inappropriate feedback. Instead, create a dummy main test which is always true, but conjoin to it (using and) a test on the Scale element (place the “select a value” feedback message in that test’s failure command) as well as a test on the Function element (place the “choose the right side instead” feedback message there). This way, the conjunction of all three tests will fail in either scenario (no choice, or invalid choice). You can place what’s common to both scenarios in the main test’s failure command to avoid redundancy:

newButton("Next")
    .center()
    .print()
    .wait(
        newVar("dummy",1).test.is(1).and( // conjoin the test on the Scale
            getScale("Conclusion").test.selected()
                .failure( getText("False").text("Select a value on the scale first") )
        ).and( // conjoin the test on the Function
            // We use the dummy array [-1,100] so that the second entry (index 1, ie value 100) is greater than 49
            newFunction( ()=>{const c=getScale("Conclusion")._element.choices; return (c[c.length-1]||[-1,100])[1]>=49;}).test.is(true)
                .failure( getText("False").text("No, one would rather use the right-hand side of the scale.") )
        )
        .failure( // This runs when the conjunction of all three tests fails
            // All this is common to the no-choice and the low-value scenarios
            getText("False").hidden()
            ,
            newTimer("wait3", 100).start().wait()
            ,
            getText("False").visible()
            ,
            newTimer("wait4", 2000).start().wait()
            ,
            getText("False").hidden()
        )
    )
,
// The code below is executed when the script moves past the wait command, ie when the test succeeds
getText("Correct")
    .hidden()
,
newTimer("wait1", 100)
    .start()
    .wait()
,
getText("Correct").visible()
,
newTimer("wait2", 4000)
    .start()
    .wait()

Jeremy