• I'm trying to test my code for Puck.js on a webpage, however I keep getting errors when trying to call the function, such as uncaught reference error when trying to execute the function. Also, errors are been returned when called puck.mag(). I've looked at the puck.html examples and I can't figure out why this is happening.

    This is my code:

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
    
        <script src="https://www.puck-js.com/puck.js"></script>    
    
        <script src="https://www.puck-js.com/puck.js">
    
            var zero = Puck.mag();
            var rep = 0;
    
            
    
            function onMag(p) {
                p.x -= zero.x;
                p.y -= zero.y;
                p.z -= zero.z;
                var s = Math.sqrt(p.x * p.x + p.y * p.y + p.z * p.z);
                if (!Boolean(s < 1000)) {
                    digitalPulse(LED2, 1, 1000);
                    rep++;
                    console.log(rep);
                }
            }
    
            Puck.on('mag', onMag);
            Puck.magOn();
    
        </script>
    </head>
    
    <body>
        
    
    <button onclick="Puck.write('LED1.set();\n');">On!</button>
    <button onclick="onMag()">puckTest</button>
    <button onclick="Puck.write('LED1.reset();\n');">Off!</button>
    </body>
    
    </html>
    
About

Avatar for Robin @Robin started