I have the problem that :return acts like an :error and terminates the function and does not execute the last command till the end of the function “}”
From the Wiki: Starting from v6.2 new syntax is added to easier define such functions and even pass parameters. It is also possible to return function value with :return command
Talked about is that it should return the value but not that the function is terminated on the spot. I read it as, that the value is returned on exit of the function.
Now I have first transfer the :global values to a temporary :local and erase the :global ones and :return the locals. The :local ones are destroyed on exit of the function.
I could switch back complete local but during debugging the environment box shows the values of variables when the are set temporary to global.
Thanks SiB and I did not see any other that :returns cuts away from the function despite there could be more instructions to process. Or did I missed it?
It has it’s chams because you can go in the middle exit a function this way without being concerned about code underneath. It brings the feeling back of a GoTo jump to me.
A beter naming for return would then be exit because return can have here two meanings, values returned or return now the values.
I avoid, if possible, global variables and prefer the self erasing of local, it not being able to life outside the scope. I expected return would help them to life outside the scope but it has it’s price this way.
Returning the value and leaving the function is the behavior for every language.
Everything else does not make sense: What would you return if the function continues and a second return is executed. How to leave the function early?
No, return is to return from a function, exit is to terminate the whole script or program.
There’s no exit in RouterOS scripting, but please do not invent it for something uncommon.
If there is a second return the that one should supersedes the earlier one and the last one the only one retuned. It is then behaving as variable, which can have only one value.
We have already :error which stops all scripts/and functions.
It seems I had them because I had to scare away people looking at their phone wandering into the garden. Never seen them personally so it was a complete surprise to me that I had them in my garden. Those invisible creatures.
Not much running scripts here and sometimes the VPN maintainers flashes by. Still debugging in terminal so maybe when it is ready.