Hi,
I’ve been struggling with a complex configuratin setup script and managed to reproduce the issue with a minimal example below.
The script calls functions, and those functions call other functions. That seems to work fine in the RouterOS console:
[admin@MikroTik] > :global myFunc do={
{... :put "enter myFunc"
{... :put "exit myFunc"
{... }
[admin@MikroTik] >
[admin@MikroTik] > :global myWrapperFunc do={
{... :put "enter myWrapperFunc"
{... $myFunc
{... :put "exit myWrapperFunc"
{... }
[admin@MikroTik] >
[admin@MikroTik] > $myWrapperFunc
enter myWrapperFunc
enter myFunc
exit myFunc
exit myWrapperFunc
[admin@MikroTik] >
But when trying executing the same lines via /import, then the inner function is silently ignored:
[admin@MikroTik] > /file print detail where name="foo.rsc"
0 name="foo.rsc" type="script" size=184 creation-time=jan/12/1970 20:49:26 contents=
:global myFunc do={
:put "enter myFunc"
:put "exit myFunc"
}
:global myWrapperFunc do={
:put "enter myWrapperFunc"
$myFunc
:put "exit myWrapperFunc"
}
$myWrapperFunc
[admin@MikroTik] > /import foo.rsc
enter myWrapperFunc
exit myWrapperFunc
Script file loaded and executed successfully
[admin@MikroTik] >
My complex setup script, organized into several .rsc files /import’ing each other, and calling functions from other functions, seems to work when the entry script is invoked via “/system reset-configuration run-after-reset=…” and in the console, but not when the entry script is invoked via /import.
I’m using RouterOS 6.24 and the model is 2011UiAS-2HnD.
Questions:
a) Why is the behaviour different between the console and the /import command?
b) How to call a function from another function, in a way that works reliably also via the /import command?
Regards,
Ulrik