fetch seems to behave different when called in function

Whole system has to fit in 16MB, so there are some limits on how many features scripting can have… so no linter to find the “use of undefined global in function”. There is “:import verbose=yes <scriptfile.rsc>” that helps find what line something is failing.

On this one:

It’s annoying & I run into it… e.g. you want a few local helper functions, but the helpers function cannot use other helper function. But… local function cannot call other local function, even if same scope (e.g. do={} function or plain block {}). That’s just how it works.

You can use recursion, with different args, to call your same global function to kinda proximate a local function calling a local function - just less procedural.

FWIW, a function can also be a member of an array. This is another approach to storing functions for re-use (e.g. a single global array, with function as named elements). But similar to locals, functions-in-array do not have access to the containing array (& limits use of array as “class”). And, confusingly, the stack gets shifted so $0 is first parameter to a function in an array (see http://forum.mikrotik.com/t/positional-arguments-in-array-function-0-vs-1/154024/1)

There are a lot of oddities in RouterOS scripting.