Community discussions

just joined
Topic Author
Posts: 1
Joined: Sun Jun 30, 2019 3:21 pm

6.44.3 Scripting - possible bug with arrays

Sun Jun 30, 2019 3:27 pm


Seems i've got a bug with arrays.
Here is minimal working script:
:global XBug1;
:global XBug2;

:if ([:typeof $XBug1] != "array") do={ :set $XBug1 [:toarray ""]; }
:if ([:typeof $XBug2] != "array") do={ :set $XBug2 [:toarray ""]; }

:local XList {"Key1";"Key2"}
:put $XList;
:put "";

:foreach XV in=$XList do={
 :local LRefBug1 {"Link"="DOWN"};
 :local LRefBug2 {"Link"="DOWN"; "ifName"=$XV};

:set ($LRefBug1->"newKey") $XV;
:set ($LRefBug2->"newKey") $XV;

:set ($XBug1->$XV) $LRefBug1;
:set ($XBug2->$XV) $LRefBug2;
Script output:
[admin@MikroTik] > :environment print                
XBug1={Key1={Link="DOWN"; newKey="Key2"}; Key2={Link="DOWN"; newKey="Key2"}}
XBug2={Key1={Link="DOWN"; ifName="Key1"; newKey="Key1"}; Key2={Link="DOWN"; ifName="Key2"; newKey="Key2"}}

What expected: value of newKey will be similar to key index (i.e. it should be "Key1" and "Key2") for both arrays.
What i've got: value of newKey in array XBug1 is the same for both keys.

My vision of situation:
During create/init :local variable mikrotik decides to create a new variable or to make reference to existing one.
If create is done with the same init string - we get reference, when init string is different - we have an independent variable.

XBug1 - created as a reference, incorrect behaviour
XBug2 - created as a new variable, works correctly

My HW: hAP ac^2, packages version 6.44.3

Who is online

Users browsing this forum: No registered users and 19 guests