When creating a label using AddLabel, I want the color of label to depend on value of variable I'm showing in the label. I could do a series If, Else if, Else if, etc., for as many colors I want to choose from. So it would look something like this:
AddLabel(yes, "Label value is: " + myVar, (if myVar > 4 then Color.BLUE else if myVar > 3 then Color.Green else if myVar > 2 then Color.Yellow else if myVar > 1 then Color.Orange [and so on]));
This is clunky and for more than a few
is super clunky and hard to read and edit down the road. And gets worse if I have multiple variables that I'm adding labels for, e.g., myVar1, myVar2, myVar3, etc.
So here's what I'm thinking and where I'm running into roadblocks:
1. can I rewrite this using Switch/Case? The cases would be potential values for myVar. For each case, I'd store the color as a variable string (I guess). How do I pass that variable string to
AddLabel(yes, myVar, Color.[need variable string to be understood as a color here])
Or perhaps it's easier to store the color as a numeric variable using the color codes and then pass that variable as the
2. if I have 1 label and 1 variable, I can place the Switch/Case just before AddLabel, and Switch will refer to myVar. But how do I efficiently extend this to multiple variables that I want to label? I could of course put a complete Switch/Case before each AddLabel. But since the cases will be the same for each variable, I'm guessing there is probably a more efficient and elegant way of doing this.