Running into JS error with MouseTracker when trials have different names

PennController for IBEX Forums Support Running into JS error with MouseTracker when trials have different names

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #8403

    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 (

    PennController.ResetPrefix(null) // Shorten command names (keep this line here)
    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'
    	"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()
    => v >= 0.75).success(end()),
    	    newText("container", "").center().css({display: "flex", 'margin-bottom': '3em'}).print(),
    	    newText("Please drag the word into the box:&nbsp;").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")
    	            getVar('responses').set(v => [true, ...v]),
    	        .offset('0.5em', '0.1em', getText('blank'))
    	    newButton("next", "Next").center().print().wait().remove()
    	    .global() => v >= 0.75)
    	            .set(v => v.filter(r => r == true).length/v.length)
    	    .set(v => Math.round(v * 100) + '%.')
    	newText("Your first-guess accuracy was&nbsp;")
    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):

    this is an item,and its condition
    • This topic was modified 1 year, 7 months ago by mawilson.
    • This topic was modified 1 year, 7 months ago by mawilson.
    • This topic was modified 1 year, 7 months ago by mawilson. Reason: code formatting

    Okay, 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,

    PennController.ResetPrefix(null) // Shorten command names (keep this line here)
        newText('').log(), // this is just so there's a result to send, otherwise it spins forever
        newMouseTracker('mouse') // comment out this line, or put it before end(), and it works
    • This reply was modified 1 year, 7 months ago by mawilson. Reason: code formatting


    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 after end(), using getMouseTracker to refer back to it


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