Depends on how you are trying to run that code, if you paste it in the terminal then whole code must be in {} braces otherwise local varaible expires in next line.
The correct behavior is on v7, the local (=discarded later) variables must not be treated as pointer, and updating local variable must not influence global variable, until is not directly wanted.
a simplified examples work identically on both v6 and v7
Can someone share a code snippet where a global array is set, then an index from that array is set in a local and when the index is changed the global reflects this change.
Shared memory is nice, as long as there the proper locks in place.
Is there a document i can read that informs of the change away from pointers? Would be nice to know what changes have been made between V6 and V7, before settling on a design pattern?
What happened on the past with nested array is a bug. If is a feature, also this must on v6 increase the TestVar value, but not happen…
{
:global TestVar
:if ([:typeof $TestVar] = "nothing") do={ :set TestVar 0 }
:local nbr1 $TestVar ; # nbr1 is not a pointer, the value is copied
:set $nbr1 ($nbr1 + 1)
:put $nbr1
:put $TestVar ; # the global var is not influenced
}
using your example, just removing one nested array, also this, if is a feature, must update main TestVar, but is not happening on v6 or on v7
{
:global TestVar;
:if ($TestVar = nil) do={
:set TestVar [:toarray ""];
:set ($TestVar->"count") 0;
}
:local nbr1 ($TestVar->"count"); # this is not one pointer, the value inside the array is copied
:set $nbr1 ($nbr1 + 1);
:put $nbr1
:put $TestVar ; # this remaining not influenced
}
I believe you. Is there any document that talks about this and other changes? Where did you learn that MT considers this a bug to be fixed in V7? Like the title says, im looking for documentation.
There is no need to see it written when it clearly works only in extreme cases and in normality it does not happen…
I repeat: if it was intended, the behavior should have been the same in the other examples,
AND ESPECIALLY there had to be a method to copy WITHOUT necessarily creating a reference that update global variable…
“change” are listed when something is done on purpose
when a bug is fixed, can be “accidentally” fixed because is not known…
for more information contact directly support@mikrotik.com and hope than some programmers reply about this bug…
There is no documentation about variable referencing because RouterOS scripting does not have referencing concept. Set should perform deep copy which it apparently did not in ROSv6.