PennController for IBEX › Forums › Support › Running into JS error with MouseTracker when trials have different names
Tagged: end(), MouseTracker
- This topic has 2 replies, 2 voices, and was last updated 2 years, 1 month ago by Jeremy.
-
AuthorPosts
-
September 13, 2022 at 6:14 pm #8403mawilsonParticipant
Apologies for the long preamble, but as far as I can tell, it’s doing all of these things at once that is causing my issue somehow.
I’m putting together an experiment where participants will be asked to drag and drop a word into a blank. I’d like to record their mouse movements as they drag the word around, so I’m using a MouseTracker element.
I’d also like to have participants repeat a training session up to two times, but end early if they reach a certain level of accuracy. I’ve followed an earlier thread here to do this, and it seems to work great!
However, I’ve decided I’d like to only repeat half of the training session at a time. The full session is a bit long, so if on a repeat participants get the first half right enough of the time, I’d like to just skip over the remaining trials. For this reason, I set up two additional separate CSVs containing the first and second halves of the training data, so that I can run participants through the full training session at least once, and then through the remaining sessions one half at a time, breaking early if they get enough right so that they don’t necessarily have to go through a full training session at a time on repeats.
The problem I am running into is that when I call the trials by different names, the script appears to freeze when the trial should be ended early. Opening the JavaScript console indicates that this is due to the following error:
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'map') at window.PennController._AddElementType.end (PennController.js:40:93530) at n.end (PennController.js:33:64935) at n.hasOwnProperty.end (PennController.js:33:48507) at b.<computed>.<computed>.h [as endTrial] (PennController.js:33:23603) at async PennController.js:33:63340
I have found two ways to avoid the error, but both involve removing functionality I’d like to keep. The first solution is removing the MouseTracker. The second solution is to repeat the entire training session.
Here’s a stripped-down MWE to show the issue (https://farm.pcibex.net/r/BtxkDp/)
PennController.ResetPrefix(null) // Shorten command names (keep this line here) DebugOff() var blank_style = { border: '1px solid #000', width: '5.75em', position: 'relative', 'padding-top': '5px', top: '-3px' } var dropped_word_style = { border: '', padding: '', width: blank_style['width'], 'text-align': 'center', 'margin-left': '-0.5em', 'margin-top': '-0px' } Sequence( "trial_train", 'post-training', // "trial_train", 'post-training', // if you uncomment this line and comment out the next line, it works (but will repeat the whole training session) "trial_train_rep1", 'post-training' ) var feedback_trial = label => item => { return newTrial(label, newVar('responses', []).global(), newVar('grandaverage', 0).global() .test.is(v => v >= 0.75).success(end()), newText("container", "").center().css({display: "flex", 'margin-bottom': '3em'}).print(), newText("Please drag the word into the box: ").print(getText("container")), newText('blank', " ").css(blank_style).print(getText("container")), newText("word", "word").css({width: '', border: '1px solid #000', padding: '3px'}).center().print(), newMouseTracker("mouse").log(), // if you comment this line out, it works newDragDrop("dd", "bungee") .log("all") .addDrop(getText('blank')) .addDrag(getText("word")) .callback( getVar('responses').set(v => [true, ...v]), getText("word").css(dropped_word_style) ) .offset('0.5em', '0.1em', getText('blank')) .wait() .removeDrag(getText("word")) .removeDrop(getText('blank')) , newButton("next", "Next").center().print().wait().remove() ) } newTrial('post-training', newVar('grandaverage') .global() .test.is(v => v >= 0.75) .failure( getVar('grandaverage') .set(getVar('responses')) .set(v => v.filter(r => r == true).length/v.length) ) , newVar('grandaveragepercent') .set(getVar('grandaverage')) .set(v => Math.round(v * 100) + '%.') , newVar('responses').global().set([]), newText("Your first-guess accuracy was ") .after(newText().text(getVar('grandaveragepercent'))) .center() .print() , newButton('Next').center().print().wait() ) Template("train.csv", feedback_trial('trial_train')) Template("train_rep1.csv", feedback_trial('trial_train_rep1'))
train.csv and train_rep1.csv are both just the following (since they’re not actually referenced in the trial template):
item,condition this is an item,and its condition
September 14, 2022 at 5:32 pm #8408mawilsonParticipantOkay, so after some testing I’ve been able to pare this issue down to what I think is the bare minimum. Using end() in a trial with a MouseTracker before the MouseTracker is initialized causes the script to freeze with the error above in the JavaScript console. Here’s a much more minimal example that shows the problem (link same as before, https://farm.pcibex.net/r/BtxkDp/):
PennController.ResetPrefix(null) // Shorten command names (keep this line here) Sequence('trial') newTrial('trial', newText('').log(), // this is just so there's a result to send, otherwise it spins forever end(), newMouseTracker('mouse') // comment out this line, or put it before end(), and it works )
- This reply was modified 2 years, 1 month ago by mawilson. Reason: code formatting
September 19, 2022 at 5:49 pm #8422JeremyKeymasterHi,
Thank you for identifying this nasty bug! I’ll make sure it doesn’t happen in the next version of PennController. In the meantime, you should create the MouseTracker element at the beginning of your trial (
newMouseTacker
) and only start it later, possibly afterend()
, usinggetMouseTracker
to refer back to itJeremy
-
AuthorPosts
- You must be logged in to reply to this topic.