Problem with :pick

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.

: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.

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 /]]"
}

Hi,

Thank you for your answers

With this solution, I have a result : “$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

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.