True false switch challenge

dynamo
#1

I need to make a 3 option switch in dynamo, made from “true” “false”. This is what I came up with. This works fine. But I know there is a better way to write this, maybe with IF else statements. I was curious to see other creative ways to slim this down further, perhaps using just design script?

1 Like
#2

Maybe with an if / elif / else statement? In this case, see here:


#3

Here’s a design script method that uses nested boolean’s, its not very slim, but it is all in a single code block, maybe that qualifies for creative at least

// if bool_1 is False
// list_1F with true and false values at index 1 & 0
// return either index 1 or 0 of list_1F depending on bool_1F
test_F = false;
test_Ff = “Ff”;
test_Ft = “Ft”;
list_1F = {test_Ff, test_Ft};
bool_1F = list_1F [test_F ? 1 : 0];

// if bool_1 is True
// list_1T with true and false values at index 1 & 0
// return either index 1 or 0 of list_1T depending on bool_1T
test_T = true;
test_Tf = “Tf”;
test_Tt = “Tt”;
list_1T = {test_Tf, test_Tt};
bool_1T = list_1T [test_T ? 1 : 0];

// bool_1
// list_1 with true and false values at index 1 & 0
// return either index 1 or 0 of list depending on bool_1
test_1 = false;
list_1 = {bool_1F, bool_1T};
bool_1 = list_1 [test_1 ? 1:0];

#4

Hi

What about this?

options = {{false, true}, {false, false},{true, false}};
out0 = options[i][0];
out1 = options[i][1];

Thomas Holth

#5

Actually the variables out0 and out1 are not necessary…

#6

Nice! I like seeing all these. Helps to see different approaches. so something like this

#7

this is a bit slimer…

//input bool tests
bool_1 = true;
bool_2 = true;

//convert bool to int as clockwork
//provide list_bool to match first index against
first_bool = {false, true};
B1 = List.FirstIndexOf(first_bool, bool_1);
B2 = List.FirstIndexOf(first_bool, bool_2);

//output index of list_string
list_string = {{“Ff”,“Ft”},{“Tf”,“Tt”}};
list_string[B1][B2];

#8

1 Like