Reply To: Display currently selected value of slider scale

PennController for IBEX Forums Support Display currently selected value of slider scale Reply To: Display currently selected value of slider scale

#8164
Jeremy
Keymaster

Hi Nadine,

Here’s how to do it:

newTrial(
    newText("scaleValue", "NA").before( newText("Score: ") )
    ,
    newScale("myScale", 7)
        .slider()
        .callback( getText("scaleValue").text(getScale("myScale")) )
        .print()
    ,
    getText("scaleValue").print()
    ,
    newButton("Next").print().wait()
)

Note that values start with 0, so if you want to display a score starting with 1, you’ll need to use a Var element:

newTrial(
    newVar("scaleVar", 0)
    ,
    newText("scaleValue", "NA").before( newText("Score: ") )
    ,
    newScale("myScale", 7)
        .slider()
        .callback( 
            getVar("scaleVar").set(getScale("myScale")).set(v=>parseInt(v)+1)
            ,
            getText("scaleValue").text( getVar("scaleVar") )
        )
        .print()
    ,
    getText("scaleValue").print()
    ,
    newButton("Next").print().wait()
)

Jeremy