-
Hi
I'm having problems to make following code work...
class GamePlay { constructor(game) { this.game = game; } activateGameButtons() { setTimeout(() => { // --- Set reset button watch setWatch( (e) => { // Check for long press... var isLong = (e.time-e.lastTime)>0.4; if (isLong) { closeApp(); } else this.resetScorePrompt(); }, BTN2, { repeat: true, debounce: 50, edge: "falling" }); },100); } resetScorePrompt() { clearWatch(); E.showPrompt("Reset the score\nto 0-0?").then( (reset) => { if (reset) { this.game.resetScore(); } this.activateGameButtons(); }); } }
After pressing BTN2 I get my prompt and when selecting "yes" or "no" I get the following error (full error in attachment):
Uncaught SyntaxError: Got => expected ',' at ....
Is there something wrong with my Javascript code ? To me it looks like arrow functions aren't supported in promises. Because in other places, arrow functions work fine. When using 'function (reset) {}' instead of '(reset) => {}' I can enter the function, but then I'm having trouble with the "this scope".
(I'm a Javascript noob, so it might just be wrong Javascript code I guess :-)) -
-
-
Hi
Below you can find some example code to illustrate my problem.
When I select "Start a game" in the menu, I start my game. But when I press BTN1 "in the game", the menu keeps flashing and when I press BTN1 / BTN2, the menu items are selected again and the game function for these buttons are activated too.
So how can I stop the built in button watches of the E.showMenu() function? Or what am I doing wrong?
Greets
Stijn
// Game functions function startGame () { g.clear(); g.setColor("#ffffff"); g.drawString("game started", 50, 100); setWatch(function() { g.clear(); g.setColor("#ffffff"); g.drawString("btn 1 pressed", 50, 110); console.log("btn 1 pressed"); }, BTN1, {repeat: true}); setWatch(function() { g.clear(); g.setColor("#ffffff"); g.drawString("btn 2 pressed", 50, 120); console.log("btn 2 pressed"); }, BTN2, {repeat: true}); } // Global functions function closeApp() { console.log("App closed"); load(); } // --- Menu var mainMenu = { "": { "title": "Menu" }, "Start a game": () => startGame(), "Exit" : () => closeApp(), }; function onInit(){ E.showMenu(mainMenu); } // --- Initialize app onInit();
-
Hi Gordon
Can you explain the difference between E.openFile and storage.open? In existing apps, I see they use "storage.open" more often than E.openFile, but it isn't clear to me when I have to use which function.
https://www.espruino.com/Reference#t_l_E_openFile
https://www.espruino.com/Reference#l_Storage_open -
-
Hi Gordon
I've tried several times to open an existing *.info file on my Bangle.js in the web IDE and saving it back to the storage (via "storage ... choose file") after making some modifications. Now the modifications aren't saved to the file when I check it again. In the console I can't find any trace/error of this save action...
The only way to make this work is to save the file locally and upload it via "device storage ... upload file".
Is this "by design"? Or is it a bug?
Thanks @Raik, changing the argument name fixed it!