Community discussions

MikroTik App
 
User avatar
xaviernuma
newbie
Topic Author
Posts: 45
Joined: Tue Feb 16, 2016 11:27 am
Location: France

Problem with :pick

Mon Apr 01, 2024 1:18 pm

Hello,

I'm facing an issue.

:global ipaddress [/queue simple get 1 target];
:global test [:find $ipaddress "/"];
The ipaddress variable returns: 192.168.0.2/32, however, test doesn't return anything. Why is that?

Thank you for your assistance.
 
msatter
Forum Guru
Forum Guru
Posts: 2915
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: Problem with :pick

Mon Apr 01, 2024 1:28 pm

:global ipaddress [/queue simple get 1 target];
:global test [:global ipaddress; :find $ipaddress "/"];
Inside the function, ipaddress is not known so you have refer to it by :global ipaddress.
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3557
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Problem with :pick  [SOLVED]

Mon Apr 01, 2024 2:51 pm

Couple other things too:
- The first line use "get 1", however that's not an *id so it depends on print being called to establish the index of 1. Using "get ([find]->0)" or "get [find name=queue1]" instead avoid needing.
- There can be multiple "target" from "/queue simple get", and :find does not work with arrays & so need use get the 1st element listed as "target" first

For example,
:global ipaddresses [/queue simple get [find name=queue1] target]
:global ipaddress [:pick $ipaddresses 0 ] 
:global cidrmark [:find  $ipaddress "/"]
:put "$[:pick $ipaddress 0 $cidrmark]"

Although these could be a locals and combined:
{
:local ipaddress ([/queue simple get [find name=queue1] target]->0); 
:put "$[:pick $ipaddress 0 [:find  $ipaddress /]]"
}
 
User avatar
xaviernuma
newbie
Topic Author
Posts: 45
Joined: Tue Feb 16, 2016 11:27 am
Location: France

Re: Problem with :pick

Mon Apr 01, 2024 9:53 pm

Hi,

Thank you for your answers
:global ipaddress [/queue simple get 1 target];
:global test [:global ipaddress; :find $ipaddress "/"];
Inside the function, ipaddress is not known so you have refer to it by :global ipaddress.
With this solution, I have a result : "$ipaddress"
Couple other things too:
- The first line use "get 1", however that's not an *id so it depends on print being called to establish the index of 1. Using "get ([find]->0)" or "get [find name=queue1]" instead avoid needing.
- There can be multiple "target" from "/queue simple get", and :find does not work with arrays & so need use get the 1st element listed as "target" first

For example,
:global ipaddresses [/queue simple get [find name=queue1] target]
:global ipaddress [:pick $ipaddresses 0 ] 
:global cidrmark [:find  $ipaddress "/"]
:put "$[:pick $ipaddress 0 $cidrmark]"

Although these could be a locals and combined:
{
:local ipaddress ([/queue simple get [find name=queue1] target]->0); 
:put "$[:pick $ipaddress 0 [:find  $ipaddress /]]"
}

- The first line use "get 1", however that's not an *id so it depends on print being called to establish the index of 1. Using "get ([find]->0)" or "get [find name=queue1]" instead avoid needing.

It was for the example, I understood that the get 1 corresponded to the number present in this menu on Winbox

- There can be multiple "target" from "/queue simple get", and :find does not work with arrays & so need use get the 1st element listed as "target" first

Indeed, you have found my problem, I had not seen this return as an array but a character string !

thanks a lot for your help

Good evening to you

Xavier
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3557
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Problem with :pick

Mon Apr 01, 2024 10:25 pm

Figured it was the array.

Anything in winbox with the <> up/down arrows next the control is generally an array in scripting. Some commands will "cast" an array of one element to str/num, but :find doesn't... So it's a bit confusing.

Who is online

Users browsing this forum: No registered users and 11 guests