You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • If you have the function handy you can do Puck.removeListener('mag', onMag) : http://www.espruino.com/Reference#l_Obje­ct_removeListener

    Note that if you do:

    function main() {
      function onMag(m) {
       m.x -= zero.x;
        m.y -= zero.y;
        m.z -= zero.z;
        var v=Math.sqrt(m.x*m.x+m.y*m.y+m.z*m.z).toF­ixed(0);
       console.log(v);
      }
       Puck.removeListener('mag', onMag);
       Puck.on('mag', onMag);
       Puck.magOn();
    }
    

    It won't work though, because onMag is basically a different function each time.

    Or you can just do Puck.removeAllListeners('mag'): http://www.espruino.com/Reference#l_Obje­ct_removeAllListeners

    But personally if you can I'd just make sure you only call Puck.on('mag', once - there's no need to call it at startup each time because Espruino will remember.

About

Avatar for Gordon @Gordon started