How do you set multiple conditions for a choice to appear

So basically I am trying to make an option appear only when one of four different variables equal 0. It looks roughly like this:

*choice
#option 1
*goto z

*if (a = 0) or (b = 0) or (c = 0) or (d = 0) #option 2
    *goto y

When I ran the random test, it keeps telling me “Invalid expression at char 11, expected no more tokens, found: CLOSE_PARENTHESIS [)]”
I am very lost. Thank you for helping out

1 Like

Look at this post, your answer is there.

1 Like

Your brackets are the cause of the problem . The correct form of your code should be like this:

Generally if you want to check more than one condition :
1- the number of brackets before the first condition should be equal to the number of your conditions
2- you should have 2 brackets after every condition except the first one (only one bracket)

Notice: The brackets control how you want the If command to be read above is the solution for your case only (which is the most common error even if you are checking more conditions than I am used to . I usually don’t check more than 3. :sweat_smile:).
And you can find here everything about how to use if statements and conditions on the Wiki

I hope I could help I had the same problem long ago and it was annoying :smiling_face_with_tear:

2 Likes

Thanks! It is very helpful!

I’m going to share the answer I gave over on reddit because while the “start with as many parentheses as you have conditions, then close out the brackets” is a good rule of thumb, if you want to make it work with “and” as well as “or” conditions you’ve got to understand the underlying principle.

The key thing with logic statements like “or” and “and” is to never give Choicescript more than 2 things to deal with at a time. Anything in parentheses can count as 1 thing.

You can manage a four-thing condition with a big stack of parentheses on one end, like folks have been suggesting here. That would turn “a + b + c + d” into (((a+b) + c) + d). The potential weakness is making sure you haven’t ended up with too many parentheses at the stack end – that can be hard to visually check (though tools like CSIDE make it easier).

You can also do it by grouping into pairs. (a + b) + (c + d) will work. Using your full example, “*if ((a = 0) or (b = 0)) or ((c = 0) or (d = 0))” would work just fine, condensing your four conditions into two sets of two.

See this thread for more examples: Is it possible... (making or/and statements with 3+ variables) - #8 by Havenstone

1 Like

Yep I know the wiki explained how if statements’ brackets work the same way as you except that you make it look easier maybe it’s experience :sweat_smile:

Actually I think that your explanation for how those brackets work will be very useful in some cases when it’s not all about checking all conditions but I would prefer the first code for some reasons like:

1- You won’t always have four conditions so you won’t always be able to have stacks which can make unnecessary confusion

2- The other code increases the chance of making mistakes which leads to some annoying bugs. You can misplace any bracket or even forget about it all together. I can’t stop imagining myself staring at this line for a long frustrating unknown amount time :disappointed:.

3- I think it will be better to follow a general rule that works with most common cases (codes) until your understanding for CS increase

1 Like

Different ways work for different people, and the “(((((((” way works for very many. :slight_smile: For a four-condition choice, I sometimes use it myself.

But that’s also about the point where I start finding it harder to parse a big stack of brackets on either side; and when we get to a six- or seven-condition choice, I definitely find e.g. “((a + b) + (c + d)) + ((e + f) + g)” easier to logic-check and keep bug-free than “(((((((a+b) + c) + d) + e) + f) + g).” The opposite will be true for some people, and that’s fine.

Regardless, it’s important to understand the “only give ChoiceScript two things at a time” principle, or else if you want to put together something with the more complex logic of mixed ors and ands, like

(((a or (b and c)) and d) or (e and f)

you won’t have a chance.

Edit: of course, you don’t have to code that level of complexity into your game in the first place. :slight_smile:

3 Likes

This topic was automatically closed 24 hours after the last reply. If you want to reopen your WiP, contact the moderators.