Holding multiple, testable values in one variable

I might be getting too fancy, but is there a way to do this that works instead of not working?

    *label holdtest
    Pick multiple colors.
      *choice
        *disable_reuse #Blue.
          *set color &"blue, "
          *goto holdtest
        *disable_reuse #Red.
          *set color &"red, "
          *goto holdtest
        *disable_reuse #Yellow.
          *set color &"yellow, "
          *goto holdtest
        #Test the color variable.
          *goto holdtest2
    *finish
    *label holdtest2
    You picked: $!{color} and that's all. Pick a color to see if choicescript can determine if the color is contained in the list or not.
    *choice
      #Blue.
        *if (color = "blue, ")
          Blue is a color in the list.
        *if (color != "blue, ")
          Either blue is not a color in the list, or choicescript failed to recognize it in the color list.  
        *goto holdtest2
      #Red.
        *if (color = "red, ")
             Red is a color in the list.
        *if (color != "red, ")
          Either red is not a color in the list, or choicescript failed to recognize it in the color list.
        *goto holdtest2
      #Yellow.
        *if (color = "yellow, ")
          Yellow is a color in the list.
        *if (color != "yellow, ")
          Either yellow is not a color in the list, or choicescript failed to recognize it in the color list.
        *goto holdtest2
    *finish

(I’ve tried it with both “if (color = “blue”)” and "if (color = "blue, “)” and neither work, unless the color picked was the only color picked.) Do I just have to suck it up and make separate “blue,” “red,” and “yellow” boolean variables?

Assuming I’m understanding what you’re asking, yes. You can’t extract part of a string from a variable. So “blue, red” != “blue”. Only “blue” = “blue”.

1 Like

Yes, that’s exactly what I was asking — and what I was hoping was not the answer. Oh well, at least I already have a workaround in mind. Onwards and upwards!

If you do come up with a workable solution please let us know, as it’s something that could be useful in various situations to streamline code.

This is something that I’ve been wanting as well. I’ve done some experimentation, but it seems that even if it is seemingly possible to simulate extracting part of a string, you’ll end up using just as many variables, or perhaps even more so than if you had done it another way.

*create d "a"
*create n "n"
*create a "d"
*create dna ""
*create anf "not"

*set dna ((d&n)&a)

${dna}
*set a "f"
*set dna ((d&n)&a)
${d}
${n}
${a}
${dna}

*if (dna = ((d&n)&a))
	Hello, 
*if (dna = "anf")
	this is true, 
*if (dna = ((d&n)&"f"))
	and so is this. 
*if ({dna} = "not")
	This as well.

This will return;

and a n f anf 
Hello, this is true, and so is this. This as well. 

I can’t really see a use for this method though.

1 Like