Hi all,
When I import a rsc file, the code executed can’t access global variables defined in the rOS main /env .
And the script can neither access variables defined in a subscript (loaded by a /import within the import script).
Here’s my test code:
[admin@MikroTik] > /file print detail where name~"test"
0 name="test.rsc" type="script" size=504 creation-time=jan/03/2002 00:12:20
contents=
#Cmd to run before importing this rsc file: :global GlobalVar "VALUE_of_GlobalVar"
:put "GlobalVar value is: $GlobalVar"
:put "Importing test-inc.rsc..."
/import test-inc.rsc\t
:put "SubScriptGlobalVar value is: $SubScriptGlobalVar"
:global ImportedScriptGlobalVar "VALUE_of_ImportedScriptGlobalVar"
:put "Just defined var ImportedScriptGlobalVar with value: $ImportedScriptGlobalVar"
#Cmd to run after importing this rsc file: :put "ImportedScriptGlobalVar value is: $ImportedScriptGlobalVar"
1 name="test-inc.rsc" type="script" size=135 creation-time=jan/03/2002 00:12:20
contents=
:global SubScriptGlobalVar "VALUE_of_SubScriptGlobalVar"
:put "Just defined var SubScriptGlobalVar with value: $SubScriptGlobalVar"
Running the test gives:
[admin@MikroTik] > /import test.rsc
GlobalVar value is:
Importing test-inc.rsc...
Just defined var SubScriptGlobalVar with value: VALUE_of_SubScriptGlobalVar
Script file loaded and executed successfully
SubScriptGlobalVar value is:
Just defined var ImportedScriptGlobalVar with value: VALUE_of_ImportedScriptGlobalVar
Script file loaded and executed successfully
See that test.rsc can’t get the value of $GlobalVar (which is defined global at a upper level) nor the one of $SubScriptGlobalVar (which is defined global at a lower level).
Test done on rOS 6.29 and 6.30.4, on a RB951G-2HnD.
BTW, as shown below, it appears that $SubScriptGlobalVar, which is defined in the subscript test-inc.rsc and not readable within test.rsc, is well propagated to the upper level at the prompt.
[admin@MikroTik] > :put "ImportedScriptGlobalVar value is: $ImportedScriptGlobalVar"
ImportedScriptGlobalVar value is: VALUE_of_ImportedScriptGlobalVar
[admin@MikroTik] > :put "SubScriptGlobalVar value is: $SubScriptGlobalVar"
SubScriptGlobalVar value is: VALUE_of_SubScriptGlobalVar
So, $SubScriptGlobalVar, defined global in test-inc.rsc, imported from test.rsc, imported from CLI, is readable from test-inc.rsc and from the CLI, but not by script that propagated from one to the other !
What a strange behavior !!! ![]()
Is this a bug, a known (undocumented ?) limitation, or am I missing something
???
In http://wiki.mikrotik.com/wiki/Manual:Scripting#Variables , I read: “global - accessible from all scripts created by current user, defined by global keyword”
Thanks for your attention and feedbacks.
Fabrice