Hi, what you're doing is fine, however you may not have to set your global variables on onInit()...
If you declare a global variable, it will be saved (along with its value) just like a function or object definition would be - so declaring them is absolutely fine.
Also, any setInterval or setWatch that was created will be remembered
onInit() will just be called once by the system at startup, after a hard reset or a call to load or save.
reset will reset the device but won't load the saved code (so won't execute onInit).
If you just send your code over to the device then you'll have to call onInit. However if you send your code to the device and then type save(), onInit will be called automatically
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.
Hi, what you're doing is fine, however you may not have to set your global variables on
onInit()
...setInterval
orsetWatch
that was created will be rememberedonInit()
will just be called once by the system at startup, after a hard reset or a call toload
orsave
.reset
will reset the device but won't load the saved code (so won't executeonInit
).If you just send your code over to the device then you'll have to call
onInit
. However if you send your code to the device and then typesave()
,onInit
will be called automatically