disable a button after selection

PennController for IBEX Forums Support disable a button after selection

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #5031
    Avery
    Participant

    Hello again,

    I have one last question! I’m trying to design a section at the beginning of the experiment in which, if the participant chooses a certain response, they cannot continue on to the experiment proper. Basically, I have two buttons, “yes” and “no”, and if they choose no, I’d like the text to change to “Please close the window” and for it to wait here, with no way to continue.

    Here is what I have:

    newTrial("NYCheck",
            newText("q","Are you currently residing in New York State?")
                .print()
            ,
            newButton("yes","Yes")
            ,
            newButton("no","No")
                .callback(
                    getText("q").text("Thank you. You may now close this window.")
                )
                .wait()
            ,
            newCanvas(200,100)
                .add(0,0,getButton("yes"))
                .add(50,0,getButton("no"))
                .print()
            ,    
            newSelector("NYChooser")
                .add( getButton("yes") , getButton("no") )
                .log()
                .once()
                .wait()
        )

    I could be going about this entirely the wrong way, but it seems that when I test what I have, it launches the experiment with the initial question text (“do you live in NY”); the buttons to choose from do not appear.

    Any advice would be welcome, thank you very much in advance!:)

    • This topic was modified 3 years, 10 months ago by Avery.
    #5033
    Jeremy
    Keymaster

    Hi,

    So what happens is that your script first prints your Text element, then creates your two Button elements without printing them, because you don’t call print on them, and then halts on the wait command of your No button. Of course you can never release the wait because the button was never printed to start with so you cannot click on it. What you want instead is something like this:

    newTrial("NYCheck",
        newText("q","Are you currently residing in New York State?")
            .print()
        ,
        newCanvas(200, 100)
          .add( 0  , 0 , newButton("yes","Yes") )
          .add( 50 , 0 , newButton("no","No")   )
          .print()
        ,
        getButton("no","No")
            .callback(
                getText("q").text("Thank you. You may now close this window.")
                ,
                getButton("no").remove(),
                getButton("yes").remove()
            )
        ,
        getButton("yes").wait() // will wait forever if button removed
    )

    Jeremy

    #5034
    Avery
    Participant

    That makes sense–dumb error on my part. Thank you!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.