Hi everybody. I’m trying to call script B from different scripts, in the same device of course. But variables declared in B are empty when used in calling scripts.
Variables that I need are declared as follows (I tried to change “local” in “global”, with same result):
Well, when I call this script from other ones, everything works fine (script are correctly run, checking out “run count”), but simply variables declared in script B are empty at the end of calling scripts…
Anyone cam help me, please? Thank you.
If the values are local, it’s normal they won’t work - as the script B has different “local” variables than the calling script.
With global values it should work. But make sure, that in the beginning of BOTH script B and calling script you declare :global xxx. And maybe use first :global xxx without the value, and then :set $xxx [value function]
If it’s only one value you need (the last one, itaTime) - you can think of making it a function, not a “script B”:
Many thanks Dasiu. I’m reading Wikipedia RouterOS Funcion. It’s very interesting and I have to thank you a lot for your precious infos.
Many thanks again.
I’m going to try.
Create this itaTime script with the definition I sent, the few line :global itaTime do={ … }
Make a scheduler to run this script every startup
In your other script in the beginning include the line:
:global itaTime
Inside the script just use the [$itaTime] “variable” (which is a function). For example:
:global itaTime
:log info "The time now is $[$itaTime]"
that’s it!
(please, remember, first to declare it in the beginning of each script using it, with just one “:global itaTime” line, without anything else, and then using it inside - as it’s like running the command)
You can also do (in your new script):
:global itaTime
:local currentItaTime [$itaTime]
:log info "The time now is $currentItaTime"