
Scope of constants - available in menus?

pokeeffe
I thought this might work at first but it had lots of problems with my kVerbosity constant - despite compilation, perhaps it's not substituted in the menu?
Submenu "Set verbosity" "\\M0::Display current level", print num2istr(NumVarOrDefault("root:Packages:LTverbosity", kVerbosity)) "\\M0::0 | Silent", /Q, lar_tools#setVerbosity(0) "\\M0::1 | Errors only", /Q, lar_tools#setVerbosity(1) "\\M0::2 | Updates on", /Q, lar_tools#setVerbosity(2) End
This version does work. I made my parameter optional and changed the return to a string reflecting current state
Submenu "Set verbosity" "\\M0::Display current level", print lar_tools#setVerbosity() "\\M0::0 | Silent", /Q, print lar_tools#setVerbosity(level=0) "\\M0::1 | Errors only", /Q, print lar_tools#setVerbosity(level=1) "\\M0::2 | Updates on", /Q, print lar_tools#setVerbosity(level=2) End
This perplexed me for quite a while - it'd be helpful to understand exactly why so I can avoid running into the same mistake
Also, here's the revised function that's called if that helps:
//------------------------------------------------------------------------------------------------------------------------------------------------------------- // setVerbosity( level ) // // Optional parameters // variable level numeric level already defined in constants (default: don't change the level) // 0=kSilent 1=kError 2=kUpdate // // Returns string indicating verbosity level when function ends Function/S setVerbosity( [level] ) variable level // set to this level If ( level<0 || level>kUpdate ) // if level out of range return "Verbosity level was not changed" // fail endif NVAR/Z verbose = root:Packages:LTverbosity // look up global holding current level If (!NVAR_exists(verbose)) // if not found DFREF savDF = GetDataFolderDFR() // save this spot NewDataFolder/O/S root:Packages // make/switch to Packages folder variable/G LTverbosity = kVerbosity // create variable & set to hardcoded default SetDataFolder savDF // return to prior location endif If (ParamIsDefault(level)) // if level wasn't specified return "Verbosity is at level "+num2istr(verbose) // return current level else // otherwise verbose = level // set global to new level return "Verbosity set to level "+num2istr(level) // return modified level endif End