Quit Trial after 3rd Attempt

PennController for IBEX Forums Support Quit Trial after 3rd Attempt

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #5148
    samsanto
    Participant

    Hello,
    I am using a template in one of my trials to go through a list of sentences and gather user input. However, if the user gets the answer wrong for the third time, I want to quit the “task” trial altogether and not finish going through the rest of the table (and move to the next trial in my sequence). I’d appreciate if you could help me with this “quit” step in the code below. I have a comment where I need it to go according to the logic I have thus far.

    PennController.Template( "fulldesign.csv" ,
        variable => PennController( "task" ,
        
            newTextInput("guess") 
            ,
            newTask(variable.sen).print()
            ,
            newText("input","Enter your guess:   ")
                .settings.after(getTextInput("guess").log("final"))
                .print()
            ,
    
            newButton("bb", "Continue").print()
            ,
            
            getButton("bb", "Continue")
                .wait( 
                    getTextInput("guess")
                        .test.text(variable.answer)
                        .failure(
                            getTextInput("guess")
                                .testNot.text("")
                                .failure(getText("warning").print())
                                .success(
                                    getVar("attempt")
                                        .set( v => v+1 )
                                    ,
                                    getVar("attempt")
                                        .test.is(3)
                                        .success(
                                            PennController.SendResults( "send" )
                                            //quit whole thing or go to different trial/screen if possible
                                        )
                                )
                        )
                )     
        )
        .log( "ParticipantID", PennController.GetURLParameter("id") )
        .log("trial", variable.n)
    );

    Thanks so much,
    Sam

    #5163
    Jeremy
    Keymaster

    Hello Sam,

    I see how things become tricky here: in order to reach the end of the trial, you will need to validate the Button’s wait command. This is fine as long as you give the correct answer, because then the test on your TextInput is a success. However, you also want to end your trial after 3 wrong answers, which means validating the wait, but we’ve already established that this situation corresponds to a failed test on your TextInput, so your wait command won’t be validated!

    One solution here is to not call wait on this specific button, but on another one instead, and handle your tests in a callback instead. I’m pasting a full functional script below: I slightly rearranged your code to my preferences, but of course feel free to move things back to how they were. I also updated the command names to reflect the changes in PennController 1.7. And finally, the AddTable bit is here just to create a table named fulldesign.csv in case someone wants to test the code who doesn’t have an appropriate table (as was my case).

    PennController.ResetPrefix(null)
    
    Sequence( "start", "task", "end" )
    
    newTrial("start", newButton("start").print().wait())
    newTrial("end", newButton("end").print().wait())
    
    AddTable("fulldesign.csv", `sen,answer,n
    what's 2+2?,4,1
    what's my cat's name?,buffy,2
    is this fun?,so-so,3`)
    
    Template( "fulldesign.csv" ,
        variable => newTrial( "task" ,
            newVar("attempt").global()
                .test.is(3).failure(
            // beginning of Var test
            newText("warning", "Your guess shouldn't be empty")
            ,
            newText(variable.sen).print()
            ,
            newText("input","Enter your guess:   ")
                .after(newTextInput("guess").log("final"))
                .print()
            ,
            getVar("attempt").set(0)
            ,
            newButton("bb", "Continue")
                .print()
                .callback( 
                    getTextInput("guess").test.text(variable.answer)
                    .failure( getTextInput("guess").test.text("")
                        .success(getText("warning").print())
                        .failure(
                            getVar("attempt").set( v => v+1 ).test.is(3)
                                .success( 
                                    getButton("bb").disable(),
                                    getButton("next").print() 
                                )
                        )
                    )
                    .success( getButton("next").click() )
                )
            ,
            newButton("next", "Sorry, you failed 3 times")
                .wait()
            // end of Var test
            )
        )
        .log( "ParticipantID", GetURLParameter("id") )
        .log("trial", variable.n)
    )

    Let me know if you have any questions

    Jeremy

    #5169
    samsanto
    Participant

    Jeremy,

    Thank you so much!! This works like a gem.

    -Sam

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