I’m still wrestling with this bit of code. Basically, I want to display the score variable after all trials, not at the end of each. So the code below is the task where the score variable is referenced and updated (‘recall’ Template) and the one-off ‘score_time’ Trial which displays the score variable.
The problems are twofold, and related: 1) where to put the score variable, and 2) how to access the score variable. I launch ‘score’ as a global variable every time, but:
– when I launch the score variable inside the ‘recall’ Template, it is not referenced later in the ‘score_time’ Trial, and ‘score_time’ only displays: ‘Your score on the recall task was: ‘ with no number (so I guess it didn’t find the ‘score’ Variable)
– when I launch the score variable outside the ‘recall’ Template, the recall score always prints as 0 in the ‘score_time’ Trial (no matter how many correct Keys I press in the trials). So I guess my code under the “question1” Key for test.pressed is not working.
Given this, it seems that launching the global score variable outside the ‘recall’ Template will at least get that variable accessible, but then I must do something that allows its value to be changed trial-by-trial, and displayed in its final, updated form at the very end. Any errors you can spot below, or any guidance you have, would be very much appreciated. Thank you so much!
Template("recall_practice_stimuli.csv", row => newTrial("recall-"+row.block, newVar("score", 0).global(), // score variable newText(row.item) .center() .css("font-size", "2em") .css("font-family", "verdana") .print() , newText("instruction", "Which condition did you encounter this word experiment? Press the F KEY for INNER, the J KEY for OUTER, and the SPACEBAR for NEW WORD") .print() , newTimer("window", 5000) .start() , newKey("question1", "FJ ") .log() .test.pressed(row.correctKey) .success(getVar("score").set(v=>v+1)) .callback(getText(row.item).remove()) .callback(getText("instruction").remove()) .callback( getTimer("window").stop() ) , getTimer("window") .wait() ) .log(row.item) .log(row.Group) .log(row.condition) .log(row.correctKey) .log("score", getVar("score")) ); newTrial("score_time", newText("Your score on the recall task was: ") .after(newText("").text(getVar("score"))) .print() .wait() );
(P.S. thank you so much for the server update – everything is running and loading so fast now!)