Community discussions

MikroTik App
 
tangram
Member Candidate
Member Candidate
Topic Author
Posts: 132
Joined: Wed Nov 16, 2016 9:55 pm

Script to edit another script

Tue Nov 14, 2017 11:48 am

Hi guys,

How do you edit a script from another script, without copy/paste the whole source ?
For example, in the script below how could I change the value from +1 to +5 or whatever from another script?

\n\t:if (\$PingFailCountISP2 < (\$FailTreshold+2)) do={\r\
\n\t\t:set PingFailCountISP2 (\$PingFailCountISP2 + 1)\r\


Sorry if this was asked before :)
 
pe1chl
Forum Guru
Forum Guru
Posts: 10529
Joined: Mon Jun 08, 2015 12:09 pm

Re: Script to edit another script

Tue Nov 14, 2017 12:01 pm

Put the "value to be added" in a :global variable and change that from the other script.
 
tangram
Member Candidate
Member Candidate
Topic Author
Posts: 132
Joined: Wed Nov 16, 2016 9:55 pm

Re: Script to edit another script

Tue Nov 14, 2017 2:03 pm

Thank you, that would definitely work. I wish that a more 'elegant' approach would exist..like ->set-find-where-something-replace but whatever works :)
 
pe1chl
Forum Guru
Forum Guru
Posts: 10529
Joined: Mon Jun 08, 2015 12:09 pm

Re: Script to edit another script

Tue Nov 14, 2017 3:17 pm

Well, I consider a global variable more elegant for the purpose that you mention than modifying the code... but to each his own.
It could be possible to get the script source in a variable (when it fits), modify something, and then re-install it, but you have to know that all scripts are "compiled" by the router, and for each change you make they have to be re-compiled.
So unless this was only an example for a more drastic change you really wanted to make, I would go for the standard practice of using variables instead of constants when their value has to be changed.
(in fact I use them even for values that are usually constant but that appear in the code multiple times, and all of them have to be the same)

Who is online

Users browsing this forum: No registered users and 35 guests