things broken in beta9

“Scripts” are not working in beta9:
[admin@MikroTik] > :foreach i in=[/interface find type=ether] do={ :put [/interface get $i name] }
Script Error: missing required values
invalid item number
Problem seems to be in ‘get’ command.

Routing marks also do not seem to be working, marks are set on packets, but seem to be ignored in routing decision.

you have to set up variables before you use them

I have read about that, but how does it apply here?
Following script works just fine:
:foreach i in=[/interface find type=ether] do={ :put $i }

I think variables are out of the question.

Yes it is a bug, foreach sets all value array to i, not just one value from array. Also it happens with disable, enable and remove commands. I hope it will be fixed in next release.

As mrz said, I have noticed it also, correct output should be:
[admin@Icarus] > :foreach i in=[/interface find type=ether] do={ :put $i }
*1
*2
*3
*5

but it is:
[admin@MikroTik] > :foreach i in=[/interface find type=ether] do={ :put $i }
*1;*2;*3;*4;*5

I think it is because find separator was changed from ‘,’ to ‘;’ and foreach still operates on ‘,’.

Separator in beta8 was ; too, this is not a problem. Problem is that, for example, find returns array values inside other arrays, while in beta8 only one array is returned.

As for arrays in arrays, I think everything in console is string based, there are no objects and/or objects in objects.

I think I was partialy right, following output is from beta9:
[admin@MikroTik] > :foreach i in=“a,b,c,d” do={ :put $i }
a
b
c
d

That means that foreach enumerates items separated by ‘,’. Since find result is separated via ‘;’, it takes a whole result as one and only item. If in beta8 everything worked fine and find was also separated with ‘;’, than between beta8 and beta9 foreach was changed “back”.

This is not exactly true. There are numerous data types in ROS scripting:

  • list
  • internal number
  • number
  • IP address
  • time
  • boolean
  • string

You can read manual for more information.
http://www.mikrotik.com/testdocs/ros/2.9/system/scripting.php

Then I might not be right at all :wink:, question than might be where the conversion occurs.
According to what I understood you before, I tried to nest one more foreach enumeration into the code, but that always resulted in crash of the console.
However since we already established that it is a bug in beta9, I’ll leave its wherebouts to the developers.

i believe once you try to change a variables value the console/script crashes. The initial assignment works. I have sent support emails about it to see if they can help.

Also - global variables - please keep them as global across the entire router, not per user.

where’s the try…catch stuff I saw that was added? I can’t seem to find reference to it anymore.

Sam