boolean switch help :)

Q and A about functionality and how to solve a special task for your application.

boolean switch help :)

Postby hgoodsir » 13 Jan 2015, 15:36

hi all, happy newyear

I have been trying to create a boolean switch and have created this using c# node
it works but very long and seems a bad way write are there any suggestion how to write this better I need to
have 20 booleans. Many thanks

switch(Input)
{
case 1:
PAPER1 = true;
PAPER2 = false;
PAPER3 = false;
PAPER4 = false;
PAPER5 = false;
PAPER6 = false;
PAPER7 = false;
PAPER8 = false;
PAPER9 = false;
PAPER10= false;
PAPER11= false;
PAPER12= false;


break;
case 2:
PAPER1 = true;
PAPER2 = true;
PAPER3 = false;
PAPER4 = false;
PAPER5 = false;
PAPER6 = false;
PAPER7 = false;
PAPER8 = false;
PAPER9 = false;
PAPER10 = false;
PAPER11 = false;
PAPER12 = false;

break;
case 3:
PAPER1 = true;
PAPER2 = true;
PAPER3 = true;
PAPER4 = false;
PAPER5 = false;
PAPER6 = false;
PAPER7 = false;
PAPER8 = false;
PAPER9 = false;
PAPER10 = false;
PAPER11 = false;
PAPER12 = false;

break;
case 4:
PAPER1 = true;
PAPER2 = true;
PAPER3 = true;
PAPER4 = true;
PAPER5 = false;
PAPER6 = false;
PAPER7 = false;
PAPER8 = false;
PAPER9 = false;
PAPER10 = false;
PAPER11 = false;
PAPER12 = false;

break;
case 5:
PAPER1 = true;
PAPER2 = true;
PAPER3 = true;
PAPER4 = true;
PAPER5 = true;
PAPER6 = false;
PAPER7 = false;
PAPER8 = false;
PAPER9 = false;
PAPER10 = false;
PAPER11 = false;
PAPER12 = false;

break;
case 6:
PAPER1 = true;
PAPER2 = true;
PAPER3 = true;
PAPER4 = true;
PAPER5 = true;
PAPER6 = true;
PAPER7 = false;
PAPER8 = false;
PAPER9 = false;
PAPER10 = false;
PAPER11 = false;
PAPER12 = false;

break;
case 7:
PAPER1 = true;
PAPER2 = true;
PAPER3 = true;
PAPER4 = true;
PAPER5 = true;
PAPER6 = true;
PAPER7 = true;
PAPER8 = false;
PAPER9 = false;
PAPER10 = false;
PAPER11 = false;
PAPER12 = false;

break;
case 8:
PAPER1 = true;
PAPER2 = true;
PAPER3 = true;
PAPER4 = true;
PAPER5 = true;
PAPER6 = true;
PAPER7 = true;
PAPER8 = true;
PAPER9 = false;
PAPER10 = false;
PAPER11 = false;
PAPER12 = false;

break;
case 9:
PAPER1 = true;
PAPER2 = true;
PAPER3 = true;
PAPER4 = true;
PAPER5 = true;
PAPER6 = true;
PAPER7 = true;
PAPER8 = true;
PAPER9 = true;
PAPER10 = false;
PAPER11 = false;
PAPER12 = false;

break;
case 10:
PAPER1 = true;
PAPER2 = true;
PAPER3 = true;
PAPER4 = true;
PAPER5 = true;
PAPER6 = true;
PAPER7 = true;
PAPER8 = true;
PAPER9 = true;
PAPER10 = true;
PAPER11 = false;
PAPER12 = false;

break;
case 11:
PAPER1 = true;
PAPER2 = true;
PAPER3 = true;
PAPER4 = true;
PAPER5 = true;
PAPER6 = true;
PAPER7 = true;
PAPER8 = true;
PAPER9 = true;
PAPER10 = true;
PAPER11 = true;
PAPER12 = false;

break;
case 12:
PAPER1 = true;
PAPER2 = true;
PAPER3 = true;
PAPER4 = true;
PAPER5 = true;
PAPER6 = true;
PAPER7 = true;
PAPER8 = true;
PAPER9 = true;
PAPER10 = true;
PAPER11 = true;
PAPER12 = true;

break;
default: OFF();
break;
User avatar
hgoodsir
 
Posts: 57
Joined: 05 Feb 2012, 16:17
Location: London

Re: boolean switch help :)

Postby lerou » 13 Jan 2015, 16:19

Hi,

depends a bit on what you're planning to do with those output bools. Here are three examples using int expressions, containers or a script with a bool array. Maybe one of those does what you want. Try not to use the script version if you need to copy it a lot.

cheers,
rou
Attachments
bools.vza
(10.74 KiB) Downloaded 133 times
User avatar
lerou
 
Posts: 222
Joined: 06 Sep 2013, 07:14
Location: Hamburg, Germany

Re: boolean switch help :)

Postby hgoodsir » 13 Jan 2015, 23:50

Many thanks rou, this helped me create what i needed which was like the switch node but inverted :)
thanks again.
Attachments
inverted_switch.vza
(14.14 KiB) Downloaded 128 times
User avatar
hgoodsir
 
Posts: 57
Joined: 05 Feb 2012, 16:17
Location: London

Re: boolean switch help :)

Postby Daniel Willer » 14 Jan 2015, 09:04

The best and simplest waz to do it is using a ValueDispatcher node.

Regards
Daniel
User avatar
Daniel Willer
 
Posts: 303
Joined: 06 Jan 2012, 18:12

Re: boolean switch help :)

Postby hgoodsir » 14 Jan 2015, 12:20

Hi Daniel,
thanks :) I posted in V4 by mistake but the place i'm at they are using ventuz 3 I wish they upgraded.
User avatar
hgoodsir
 
Posts: 57
Joined: 05 Feb 2012, 16:17
Location: London

Re: boolean switch help :)

Postby Daniel Willer » 14 Jan 2015, 13:43

Ok I move the topic to V3.
User avatar
Daniel Willer
 
Posts: 303
Joined: 06 Jan 2012, 18:12

Re: boolean switch help :)

Postby lerou » 14 Jan 2015, 13:47

He wanted all outputs i with i <= n to be true, the rest to be false. I don't think the dispatcher can do that, can it?

cheers,
rou
User avatar
lerou
 
Posts: 222
Joined: 06 Sep 2013, 07:14
Location: Hamburg, Germany

Re: boolean switch help :)

Postby amarisJones » 07 Mar 2016, 09:34

I have been concerned about this topic and have been looking for answers. Hoping to find the best solution, we look forward to your sharing. Thank you.
Fashion bubble football : Bumper ball
amarisJones
 
Posts: 2
Joined: 07 Mar 2016, 04:41


Return to How to...