Confusing changes to code made by save() - dump() #3972
Replies: 1 comment
-
Posted at 2014-07-22 by Stuart.d.d Sorry about the mess but the formatting seems to be messed up. If yo uneed separate copies of the files I can provide. Stuart Posted at 2014-07-22 by @gfwilliams The issue with the code not displaying is that you need a newline before and after each section of code that you paste in... I think the main issue you're hitting here is that when you send code to Espruino from the right-hand pane, it's executed immediately. That means if you say:
Then It's most noticeable for To get around this, it's best to put code that you want to start into a function called
Having said that, there seem to be other issues:
Posted at 2014-07-22 by @gfwilliams Just wanted to add that while Espruino has a hard time turning its internal state back into text, it doesn't mean that I think that in your case, using your existing code and just saving before you press BTN1 would solve your problems. At least it worked for me :) Posted at 2014-07-22 by Stuart.d.d Thanks for the reply. Thanks for the reformatted code I will give it a try. I can see the logic now so it makes sense. Coming from a Java background you may see where my confusion stems from. My process was to upload the code, then press the button, then save(), then do the dump(). Am I right is saying that the current value of the var's is wirtten to flash with the source when a save() is run and dump inlines the values with the source. So onInit() is run on reset, reset() and power-up. Is it run on load() as well. I do think the coding examples need to show this feature of the language. Posted at 2014-07-22 by @gfwilliams
Not quite. I did it :)
Yes, so it saved the state of the board after you'd pressed the button :)
Yes, that's basically right - except So:
It's a bit different to a compiled language, but it makes sense as there isn't space for it to store both the original state and the new state at once. There is some at the bottom of the Quick Start:
and it's touched on slightly in Troubleshooting. It's hard to know where people will look for it though! It seems most people (like me) don't read much of the documentation until they actually have a problem! Posted at 2014-07-24 by Stuart.d.d OK - Thanks for sorting it out. This is really useful if when the code does a save() all state is saved, it means that after a power down and reboot the state is restored. I assume the local variables in onInit() are not saved, just the globals. Thanks for the response. Very encouraging. All I need now is for Espruino to run bare metal on a RaspberryPi...... Put it on my wish list! Posted at 2014-07-24 by @gfwilliams Everything is saved that you'd expect if you took a 'snapshot' of memory... So:
will print '42' the next time around, even if it's not global. The one 'gotcha' is that
Will print 'Hello', then 'World', then it will save the state. It's probably not a nightmare to run Espruino bare-metal on the Pi, but the second you want USB/Ethernet/Video/Sound/etc it's going to turn into an enormous amount of work :) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2014-07-22 by Stuart.d.d
Hi
Love the Espruino. Having loads of fun seeing what it can do. However have issue that is confusing me. Can somone help.
I wrote the following code...
This works fine, my lights blink, my servo moves...
When I save() and reset the code does not start! However if I press the button it does get to the setWatch function and the device works from there.
If I do a dump() however there are some confusing changes to the code.
var step is set to 5, somtimes 7... never 0;
var servoPos = 2.34. However if I run from console I get the following:
also the line
is re-written as:
and the var timer is not set and timervar is introduced. This is a mix of
and
Finally the setWatch parameters are missing the "debounce":10
I updated to 1v67.. Read some entries in the forum and downgraded to 1v66 but it still does not work.
When I received Espruino I updated straight away and did not see and evidence of this. that was about a week ago. however in my excitement I did not note which version it upgraded to.
Currently it works from ram not from flash. If I reset() in the console(), press the reset button, disconnect battery and re-connect or load() in the console it does NOT run.
It tried minification on and off. It still does not work...
Can you please help...
Stuart
Beta Was this translation helpful? Give feedback.
All reactions