Community discussions

MikroTik App
 
eldoncito2019
Member
Member
Topic Author
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Use global variable that already exists in another script

Mon Apr 25, 2022 5:42 pm

Guys, I have this global variable in another script and I would like to use it in another script, how would it be?

:global stopRouterRun false

:do {
             

           :delay 60
} while=(!$stopRouterRun)


EL DONCITO.
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3253
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Use global variable that already exists in another script

Mon Apr 25, 2022 5:58 pm

This is in the docs, https://help.mikrotik.com/docs/display/ ... -Variables:
Every variable, except for built-in RouterOS variables, must be declared before usage by local or global keywords. Undefined variables will be marked as undefined and will result in a compilation error.
So if stopRouterRun in your case was defined and assigned as value like "false" elsewhere. You can just remove the assignment in your code above:
:global stopRouterRun
:do {
           :delay 60
} while=(!$stopRouterRun)
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3253
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Use global variable that already exists in another script

Mon Apr 25, 2022 6:08 pm

@eldoncito2019, it seems like you're re-inventing the wheel, and posting with a question as your attaching each spoke.

There are few script libraries people have written that have a lot of useful "helper functions". You can search the forum for most scripting needs and someone likely already has written a script that can adapted. There are quite a few on GitHub, like https://github.com/eworm-de/routeros-scripts and https://github.com/merlinthemagic/MTM-R ... -Scripting that may give you ideas, or may be a better place to start than a blank canvas script.
 
eldoncito2019
Member
Member
Topic Author
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Re: Use global variable that already exists in another script  [SOLVED]

Mon Apr 25, 2022 8:03 pm

Thanks for your help Amm0, I already solved my problem


:global stopRouterRun
:put $stopRouterRun 

:do {
      
      
      
      :delay 60
} while=(!$stopRouterRun)



EL DONCITO

Who is online

Users browsing this forum: No registered users and 12 guests