Community discussions

 
sin3vil
just joined
Topic Author
Posts: 2
Joined: Sat May 26, 2018 10:05 pm

:tobool not working as expected

Thu Jun 13, 2019 5:41 pm

Hello,

Can someone explain why this isn't working?
[admin@MikroTik] > local string "true";local boolean [:tobool $string];put [typeof $boolean]
nil
Tested on 6.44.1 and 6.45beta27.
 
User avatar
ADahi
Member Candidate
Member Candidate
Posts: 217
Joined: Thu Sep 21, 2017 7:16 pm
Location: Iraq, Ninavah
Contact:

Re: :tobool not working as expected

Thu Jun 13, 2019 7:03 pm

try remove "" from string
 
User avatar
vecernik87
Long time Member
Long time Member
Posts: 638
Joined: Fri Nov 10, 2017 8:19 am

Re: :tobool not working as expected

Fri Jun 14, 2019 3:40 am

@ADahi: That is not a solution. He clearly wants to work with string. If you do
local string true;
, then you got variable named "string" containing boolean value. There would be no point in converting it to boolean if it already is boolean.

@sin3vil:
If you really require it to work with "true" and "false" strings, you can use condition:
local string "true";local boolean (string="true");put [typeof $boolean];put [$boolean]
I am not quite sure why your code does not work, but it seems that
:tobool
is really broken. I tried to use as parameter true/false, yes/no, 1/0 (both string or integer) and it does not produce any result. I can't figure out what possible input I need to use in order to get boolean result.
On the other hand, my proposed solution is actually shorter than your original idea - I guess no reason to use this conversion command at all.
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 5841
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: :tobool not working as expected

Fri Jun 14, 2019 1:22 pm

Currently :tobool does not work at all. If you could list all values that you would like to convert then we can try to implement it.

Who is online

Users browsing this forum: No registered users and 6 guests