Community discussions

MikroTik App
 
User avatar
cmdorexe
just joined
Topic Author
Posts: 12
Joined: Sun Sep 11, 2016 1:12 pm
Location: Nizhny Novgorod, Russia

macros bug

Fri Mar 22, 2019 1:34 am

as example if+else not work
global test yes
/log info [:typeof $test]
/log info [:typeof yes]
/log info ( yes = yes )
/log info ( $test = yes )
global print do={
  if ( $test = yes) do={/log info yes} else={/log info no}
}
$print
global test no
$print
I'm not understand why? Anybody have some sojestion with it.
 
Van9018
Long time Member
Long time Member
Posts: 558
Joined: Mon Jun 16, 2014 6:26 pm
Location: Canada - Abbotsford

Re: macros bug

Fri Mar 22, 2019 5:03 am

This page: https://wiki.mikrotik.com/wiki/Manual:S ... _statement
says the syntax of the if statement should be prefixed with a colon

{
:local myBool true;
:if ($myBool = false) do={ :put "value is false" } else={ :put "value is true" }
}
 
User avatar
cmdorexe
just joined
Topic Author
Posts: 12
Joined: Sun Sep 11, 2016 1:12 pm
Location: Nizhny Novgorod, Russia

Re: macros bug

Fri Mar 29, 2019 5:10 pm

It's not working in scripts with log. if i did it in terminal it's work perfect.
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: macros bug

Fri Mar 29, 2019 11:02 pm

It's not working in scripts with log
Any details? Because my "details" work fine...
Screen Shot 2019-03-29 at 23.39.48.png
You do not have the required permissions to view the files attached to this post.
 
User avatar
BlackVS
Member Candidate
Member Candidate
Posts: 172
Joined: Mon Feb 04, 2013 7:00 pm
Contact:

Re: macros bug

Wed Apr 03, 2019 2:50 pm

Works in my case (the same result as in Chupaka) - CCR1009, the last firmware. Just copied your code in script called test_if and called it from terminal.
 
Chupakabra303
just joined
Posts: 14
Joined: Tue Jun 20, 2017 3:07 pm

Re: macros bug  [SOLVED]

Thu Apr 18, 2019 11:42 am

It's not working in scripts with log. if i did it in terminal it's work perfect.
Declare a global variable before use in function!
global print do={
:global test
if ( $test = yes) do={/log info yes} else={/log info no}
}
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: macros bug

Thu Apr 18, 2019 11:56 am

if ( $test = yes) do={/log info yes} else={/log info no}
Will not work, you need to double quote yes like this:
if ( $test = "yes") do={/log info "yes"} else={/log info "no"}

To test things out:
:global test "yes"
[
:global test
if ( $test = "yes") do={:put "true"} else={:put "false"}
]
prints true to screen

and
:global test "no"
[
:global test
if ( $test = "yes") do={:put "true"} else={:put "false"}
]
prints false to screen
 
User avatar
cmdorexe
just joined
Topic Author
Posts: 12
Joined: Sun Sep 11, 2016 1:12 pm
Location: Nizhny Novgorod, Russia

Re: macros bug

Thu Jun 27, 2019 3:13 pm

Will not work, you need to double quote yes like this:
if ( $test = "yes") do={/log info "yes"} else={/log info "no"}
it's string not bool! I'm write about bool's in scripts!
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: macros bug

Thu Jun 27, 2019 7:46 pm

Then I do not understand what you try to do.
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: macros bug

Sat Jun 29, 2019 7:58 am

So what's exactly not working?
 
User avatar
cmdorexe
just joined
Topic Author
Posts: 12
Joined: Sun Sep 11, 2016 1:12 pm
Location: Nizhny Novgorod, Russia

Re: macros bug

Wed Jul 17, 2019 8:04 pm

bool1.png
bool2.png
You do not have the required permissions to view the files attached to this post.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: macros bug

Wed Jul 17, 2019 9:13 pm

So what's exactly not working?
@cmdorexe
You do just show some code and does not respond to the question. What does not work?


If you try to run a script from cli, you need to wrap it in {}

Example
:local test "more"
:put $test
Needs to be
{
:local test "more"
:put $test
}
This do work also
[
:local test "more"
:put $test
]
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: macros bug

Thu Jul 18, 2019 7:33 pm

Oh, I see. That will do the trick:
:global test yes
:global print do={
  :global test
  if ( $test = yes) do={/log info yes} else={/log info no}
}
$print
:global test no
$print
By ":global test" you're saying you need to use 'test' global var in current visibility scope (function body).
 
User avatar
Chupaka
Forum Guru
Forum Guru
Posts: 8709
Joined: Mon Jun 19, 2006 11:15 pm
Location: Minsk, Belarus
Contact:

Re: macros bug

Thu Jul 18, 2019 7:35 pm

Or you can pass the var into function explicitly:
:global test yes
:global print do={
  if ( $test = yes) do={/log info yes} else={/log info no}
}
$print test=$test
:global test no
$print test=$test
 
User avatar
cmdorexe
just joined
Topic Author
Posts: 12
Joined: Sun Sep 11, 2016 1:12 pm
Location: Nizhny Novgorod, Russia

Re: macros bug

Fri Jul 19, 2019 8:45 am

Or you can pass the var into function explicitly:
wow n1ce trick. I never known.

Who is online

Users browsing this forum: No registered users and 19 guests