convert boolean true or false into float in a float script controller?

convert boolean true or false into float in a float script controller?

Anonymous
Not applicable
2,906 Views
4 Replies
Message 1 of 5

convert boolean true or false into float in a float script controller?

Anonymous
Not applicable

Hello friends, here I am with noob questions again.

 

My need is simple: I want to switch controllers in a list on or off using a custom attribute with a boolean checkbox.

 

If I debug the float script, i can see that switch (my variable) evaluates to true or false.

 

So what I'm trying is:

 

if switch = true
then 1.0
else if switch = false
then 0.0
else switch

 

The script evaluates to 0.0 no matter what the switch is set to.

 

Why doesn't this work? Thanks in advance for your time.

0 Likes
Accepted solutions (1)
2,907 Views
4 Replies
Replies (4)
Message 2 of 5

Steve_Curley
Mentor
Mentor
Accepted solution
= is for assignment, == is for tests. You need to use == in your example.
Also, you don't need to test for equality - "if switch then" is equivalent to "if switch == true then".

Your code, assuming you're using the Checked property, makes no sense as "switch" can only ever be true or false - you only need one test, but you're catering for 3 conditions (which would only be correct if you used Tristate instead of Checked, but then the tests would be incorrect as Tristate is an integer, not a boolean).

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 3 of 5

Anonymous
Not applicable

Thanks very much, Steve. I tried this:

 

if switch == false
then 0
else if switch == true
then 1

 

And  it's evaluating 0 or 1. I think the info about == being for tests made the difference.

 

Great forum. Thanks again!

0 Likes
Message 4 of 5

Steve_Curley
Mentor
Mentor
You still only need one test:-
if switch then 1 else 0
-- or
if (switch == True) then 1 else 0
Or
if (not switch) then 0 else 1
-- or
if (switch == False) then 0 else 1
You don't need to test both conditions because failing one condition means the variable is, by definition, the other condition - booleans can only have 2 states.

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 5 of 5

Anonymous
Not applicable

Ah!

 

Ok thanks, Steve, putting that in the memory banks now. Much appreciated.

0 Likes