Using loop functions in rsc-files

Hey guys,
quick question here.
I’m using rsc-files to configure my devices. Now when i try to use loop statements in the file, it won’t load.
Is it generally not possible to use loops or am i doing something wrong?

Thanks a million in advance
J.

I would suggest you create a script into your rsc file and call it after creation.
Then, your script can include any loop supported by the Mikrotik scripting language.
E.g

/your commands
/system script
add name=your_script_name ....\
...\
...
/system script run your_script_name

For more information about Mikrotik Scripting see:
https://wiki.mikrotik.com/wiki/Manual:Scripting

I hope this could help you.

put your script here

Thank you guys,
@ochaconm
ok, this sort of leads me to another question:

  • would variable values created in an external script be available to the calling script (using ":global" they should, right?) and
  • would they be available fast enough?

@BlackVS
it goes something like:

:global AR [:toarray 1,2,3,4]
:global a "111"
:global b "222"
.
.
:global x "999"
:foreach i in=$AR do={:set $x ($x , ( $i . "00"))}

All variables up till this "foreach"-statement are available, but not the new value of $x and none of the configuration, coded by the following lines will get applied.
... Terminal will output: "script executed successfully" though.

From some quick tests, :global works as expected… The tricky part is to use it without a value in script in order to import a variable without setting it.

If you call :global WITH a value, you are effectively setting its value to the one specified… The difference with “:set” being that the variable is declared if it doesn’t exist.

if you call :global WITHOUT a value, you are either creating the variable with a value of “nothing” (if it doesn’t exist), or importing it with its current value if it does exist.

You should initialize your global variables in a separate script (perhaps at startup), and in all other scripts, just call :global without a value to import the variable.