I've hit that problem a few times. e.g. right now one of my Puck.write() calls is working but when I follow it with a Puck.eval(), it throws a JSON error which turns out to be due to trying to parse
Still trying to figure out what interaction of write() and eval() is causing that to appear as the response to eval(). Doing two eval() in a row is fine. And if I do write(), eval(), eval(), the second eval() is fine so write() is causing some issue.
<html>
<head>
</head>
<body>
<script src="https://www.puck-js.com/puck.js"></script>
<script>
var d = new Date();
var n = Math.round(d.getTime()/1000);
var puckCommand = "setTime(" + n + ")\\n";
console.log(puckCommand);
</script>
<button onclick="Puck.write(puckCommand);">Set The Time</button>
<button onclick="Puck.eval('new Date().toString()',function(x) { console.log(x); })">Get The Time</button>
</body>
</html>
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
I've hit that problem a few times. e.g. right now one of my Puck.write() calls is working but when I follow it with a Puck.eval(), it throws a JSON error which turns out to be due to trying to parse
Still trying to figure out what interaction of write() and eval() is causing that to appear as the response to eval(). Doing two eval() in a row is fine. And if I do write(), eval(), eval(), the second eval() is fine so write() is causing some issue.