Reply To: Conditional training phase

PennController for IBEX Forums Support Conditional training phase Reply To: Conditional training phase

#7130
Jeremy
Keymaster

Hi,

The code you posted has several syntax errors that make it crash. If it comes from an existing project, please consider sharing the demonstration link. Or, if you directly report some code here, try to copy-paste it from the existing project so no new errors are introduced in the process

This is the code I tested myself, after fixing the syntax errors:

AddTable("LEX",`WORDS,RES
PLATERY,F
DENIAL,J
GENERIC,J
MENSIBLE,F
SCORNFUL,J
STOUTLY,J
ABLAZE,J
JERMSHAW,F`)

Template("LEX", row=> 
    newTrial("Engl_prof",
        newVar("score", 0).global()
        ,
        newText(row.WORDS).print("center at 50vw","middle at 50vh")
        ,
        newText("<span style='color:red'><b>F = it doesn't exist</span>>/b>, <span style='color:green'><b>J = it exists</span></b>")
            .print("center at 50vw","middle at 75vh")
        ,
        newKey("lext","FJ")
            .wait()
            .log()
            .callback(
                getKey("lext")
                    .test.pressed(row.RES)
                    .success(getVar("score").set(v=>v+1))
            )
    )
)

newTrial("result",
    newVar("score").global(),
    newText("yscore")
        .before(newText("Your score is: "))
        .text(getVar("score"))
        .after(newText("/60"))
        .print()
    ,
    newButton("Ok").print().wait(),
    newVar("score").global(),
    getVar("score").test.is( v => v > 41 )
        .success(end)
        .failure( newText("I'm sorry but your score is too low. You cannot continue the experiment.").print().wait() )
        
)

When I ran the experiment, the debugger immediately reported an error:

Ambiguous use of getVar(“score”): more than one elements were created with that name-- getVar(“score”) will refer to the first one

Indeed, in the second newTrial you create the “score” Var element twice, so I took the second one out, and then I was able to run the experiment with no warnings or errors

Your main problem here is that you associate a callback to the Key element after a keypress happened. In fact you don’t need to use callback at all: all you want to do is wait for a keypress, and do something after that (namely, a test) and wait already gives you that:

newKey("lext","FJ")
    .wait()
    .log()
    .test.pressed(row.RES)
    .success(getVar("score").set(v=>v+1))

Now, your “result” (“resul” in your original code) trial checks whether the value of the “score” Var element is greater than 41, but since your table only defines 8 trials, of course you’ll never pass that threshold, even with a perfect score. 70% of 8 is 5.6, so you could replace 41 with 5. You could also print the “OK” button only if the test is a success, thus only letting the accurate participants continue:

newTrial("result",
    newVar("score").global(),
    newText("yscore")
        .before(newText("Your score is: "))
        .text(getVar("score"))
        .after(newText("/8"))
        .print()
    ,
    newButton("Ok"),
    getVar("score").test.is( v => v > 5 )
        .success(getButton("OK").print())
        .failure( newText("I'm sorry but your score is too low. You cannot continue the experiment.").print() )
    ,
    getButton("OK").wait()
)

One caveat: it is against some recruitment platforms’ policies (and maybe some IRB policies?) to prevent a participant who started your experiment from completing it, so this is something you might want to double-check

Jeremy