Script works perfectly in terminal, but stops if its a script?

Can anyone shed some light on to this? I’ve written a script that works flawlessly when i put it into terminal (starting with [, pasting in, then finishing with ])

:log info “running”;
:local blink false;
:local int PortBlink;
:log info “test”;
:foreach i in [/interface wireless registration-table find] do={;
:log info “test2”;
:if ([get $i interface] = “PortBlink”) do={:set blink true};
:log info “test3”;
};
:log info “test4”;

But when paste it in as an actual script, run it and check the logs it’s only getting to “test2” and stops. Can anyone help me with this?

Put this as top line: /interface wireless

works (except had to be /interface wireless registration-table)
Thank you, wish MikroTik would hurry up and implement some proper script debugging… if it spat out ‘invalid command’ because it was executing in the wrong section it would have made troubleshooting a whole lot easier

Yes there totally no detailed info when a script is not completing or crashes. I did some scripting lately and you made the same mistake as I did by already being in the correct section when testing in the terminal. Scripting is always from the root and if you have to different sections you have to put the path in each line or easier before each section if it are more lines in the same section.

If a script error is logged what is the trouble to put in the text part of the line just the script name + command line executed on which the script did not execute the line.

I suggest to do the following when the script is not working as suspected “/system script edit script_name source”. Through CLI syntax highlighting will work and you should be able to see where the problem is.

That is of some help, but still it would be nice if a script error was logged when scripts are running in some invisible context.
I have been debugging 1-line on-up and on-down scripts for a ppp profile recently and it is no fun.
(also because the variable substitution and expression evaluation is not as general as it could be, so it is often required
to e.g. set variable to expression and then use the variable in the next statement, instead of using the expression directly)

There appears to be a bug in this feature. It displays the script double-spaced (one empty line between each script line) and cursor movement is not correct.
When using “/system script print” the output looks OK.

However, what is really required is that all script output from scripts that are not launched from a terminal (scheduled, or attached to an event) send all their output (both :put and error messages) to the log. When you don’t want to upset existing systems with lots of logging that was never there, just log it as “script, debug”. Then at least we can debug things.
Also, PLEASE make the error messages more specific. “no such item” then at least indicate what item and what line/position.