Are in local variables only lowercase characters allowed?
I have a strange behaviour within a script.
:local LtgGefunden false;
:set LtgGefunden true;
:if (LtgGefunden = true) do={
:log info "correct behaviour";
} else={
:log info "oops thats wrong"
};
The behaviour of the script depends on the characters
of the local variable. If there is an uppercase character
in the name of the variable the IF condition fails.
:local L tgG efunden => IF condition fails
:local ltgG efunden => IF condition fails
:local ltggeF unden => IF condition fails
:local ltggefunden => IF condition works
I checked the value of the variable before the IF condition and the value is always equal true.
I use 6.17 on a RB2011 and CCR-1016.
Any idea what´s going wrong here?
FIrst of all, you must write correct syntax, is near all wrong:
:local LtgGefunden value=false;
:set $LtgGefunden value=true;
:if ($LtgGefunden = true) do={
:log info message=“correct behaviour”;
} else={
:log info message=“oops thats wrong”;
};
Hi rextended
it´s the syntax written on the wiki page: http://wiki.mikrotik.com/wiki/Manual:Scripting
Examples:
:global a; :set a true;
:log info “Hello from script”;
But you are right, there is an syntax error in the IF condition I didn´t notice.
The $ was missing. With $ script works.
Thanks.
mrz
August 4, 2014, 1:05pm
4
value= and message= is not necessary $ in set command is not necessary
$ was missing in this line :if ($LtgGefunden = true) do={
On RouterOS 6.7:
[admin@Gateway] > :set x value=3;
expected variable name (line 1 column 6)
[admin@Gateway] > :global x value=3;
[admin@Gateway] > :set x value=3;
[admin@Gateway] > :set $x value=3;
expected variable name (line 1 column 6)
On RouterOS 6.18:
[admin@MATRIX] > :set x value=2;
syntax error (line 1 column 6)
[admin@MATRIX] > :global x value=1;
[admin@MATRIX] > :set x value=2;
[admin@MATRIX] > :put $x;
2
[admin@MATRIX] > :set $x value=3; <<<<< now this instruction do not do error. On 6.7 yes.
[admin@MATRIX] > :put $x;
3
[admin@MATRIX] >
:set has this command line:
:set name= value=
I’m expecting:
:global varname value=test;
:global test value=0;
:set test value=7;
At this point I’m expecting test = 7, and is.
But if I write:
:set $varname value=666;
I’m expecting at this point, set the variable named with the name inside varname to 666:
varname=test
test=666
But… is not.
Is this:
varname=666
test=7
mrz
August 5, 2014, 7:57am
6
Nested variables are not supported in RouterOS.
v6.18 just has more relaxed syntax. :set x 3 is the same as :set $x 3
What you could do is make an array and then access array elements by keys.
:global a;
:set ($a->“x”) 1;
:set ($a->“y”) 2;
:put ($a->“x”);
mrz:
Nested variables are not supported in RouterOS.
v6.18 just has more relaxed syntax. :set x 3 is the same as :set $x 3
What you could do is make an array and then access array elements by keys.
:global a;
:set ($a->“x”) 1;
:set ($a->“y”) 2;
:put ($a->“x”);
Thanks for the detailed reply