Modules.addCached inside switch statement

Posted on
  • Hi Gordon

    this works:

    Modules.addCached('SM',''):
    

    When i call addCached inside a switch statement like this:

    var totest='exp';
    switch(totest) {
                case 'exp':
                      Modules.addCached('SM','');
                     break;
                case 'nxt':
                     break;
    }
    
    
    Uncaught SyntaxError: BREAK statement outside of SWITCH, FOR or WHILE loop
     at line 1 col 52
    ...Modules.addCached('SM','');break;caseĀ­'nxt':break;}
                                  ^
    
  • Espruino Version:

    1v81.149 Copyright 2015 G.Williams

  • Thanks - seems like an issue with addCached resetting the state then. I'll file a bug for it.

    To be honest it's really not meant to be used like that - it's literally just for loading a module in right at the start of the code. What were you trying to achieve? There might be an easier way?

  • ...looks like the idea of loading moudules one after the ohter for testing purposes... does this come close? (Edited: ...obviously not)

  • Hi Gordon

    No Problem. I transfer additional code via xbee to my espruino's as needed.
    I tried to implement this with own local modules. Load them dynamicaly via xbee using addCached. Maybe it's better to implement it via eval.

    Sacha

  • @Sacha I think for the moment it might be better with eval - sorry! To be honest that's almost exactly what addCached does behind the scenes anyway.

  • Will do so. Thanks.

  • I've used Module.addCached successfull. Moved it temporarly out of the switch/case statment within a function. It's better than using eval. I can allways see and manage the loaded modules.

    My prototype is now able to load and replace modules via xbee without interupting or reset the pico. Very nice!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Modules.addCached inside switch statement

Posted by Avatar for Sacha @Sacha

Actions