Community discussions

MikroTik App
 
Wublide
newbie
Topic Author
Posts: 30
Joined: Sun Feb 18, 2018 11:00 pm

Help with if statement script

Tue Mar 14, 2023 1:48 pm

I need to create an if statement based on a condition that the $leaseActMAC is not equal to some mac address in a fixed array, how do I achieve that?
:local mac {"00:11:22:33:44:AA"; "00:11:22:33:44:BB"; "00:11:22:33:44:CC"}
:if ($leaseActMAC != $mac) do {
is this code snippet correct?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Help with if statement script

Tue Mar 14, 2023 2:14 pm

You need to translate YOUR need into code...
Pratically you want FIND inside $mac array if at least $leaseActMAC is present at least one time...
:local mac {"00:11:22:33:44:AA"; "00:11:22:33:44:BB"; "00:11:22:33:44:CC"}
:if ([:find $mac $leaseActMAC] > 0) do={
( do not forget = between do and { )
 
Wublide
newbie
Topic Author
Posts: 30
Joined: Sun Feb 18, 2018 11:00 pm

Re: Help with if statement script

Tue Mar 14, 2023 2:40 pm

You need to translate YOUR need into code...
Pratically you want FIND inside $mac array if at least $leaseActMAC is present at least one time...
:local mac {"00:11:22:33:44:AA"; "00:11:22:33:44:BB"; "00:11:22:33:44:CC"}
:if ([:find $mac $leaseActMAC] > 0) do={
( do not forget = between do and { )
thank you for the syntax help!
but shouldn't it be
:if ([:find $mac $leaseActMAC] = 0) do={
to execute the if statement when $leaseActMAC is not equal to that address array?
are those quotes in the array mandatory?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Help with if statement script

Tue Mar 14, 2023 3:00 pm

Ah, I forgot the ! on translation....
The " " ara mandatory, do not exist "one array of MACs", but "array of strings".

Or you find something, or you find "nil", you can not have zero, 0 is a result, and find is not a "count"... If the find not find you find nothig, "nil"....

if you didn't find it in the array then...
:local mac {"00:11:22:33:44:AA"; "00:11:22:33:44:BB"; "00:11:22:33:44:CC"}
:if ([:typeof [:find $mac $leaseActMAC]] = "nil") do={
 
Wublide
newbie
Topic Author
Posts: 30
Joined: Sun Feb 18, 2018 11:00 pm

Re: Help with if statement script

Tue Mar 14, 2023 3:19 pm

you've been beautifully clear, it worked out flawlessly, thank you a lot @rextended

Who is online

Users browsing this forum: No registered users and 34 guests