Is the code correct?

Can I use multiple *if statements inside an option like this?

*selectable_if ((have_weapon = "yes") and (weapon_health > 0) and (stamina >= 10) and (ultra_attack = "learned") and (combat_type = "strongarm")) # Put full strength behind your slashes! Attack everyone!
*selectable_if (((((have_weapon) and (weapon_health > 0)) and (stamina >= 10)) and (ultra_attack = "learned")) and (combat_type = "strongarm")) #Put full strength behind your slashes! Attack everyone!

Like this I think (made ‘have_weapon’ a true/false variable here)

3 Likes

Oh wow! You’re a lifesaver! It actually works! I’m not getting the error anymore. Thanks lots dude :+1:.

3 Likes

So that’s how it works, thank you for showing me melting.

2 Likes

The key principle: only ever give ChoiceScript a maximum of two things at a time; anything in parentheses counts as one thing.

The method Meeps has shown you effectively starts by grouping these two things

(have_weapon = "yes") and (weapon_health > 0)

into one thing

((have_weapon = "yes") and (weapon_health > 0))

which lets you adds the next term as a second thing

((have_weapon = "yes") and (weapon_health > 0)) and (stamina >= 10)

and then turn that into one thing by slapping a new set of parens around it

(((have_weapon = "yes") and (weapon_health > 0)) and (stamina >= 10))

and so on. In the end, you could end up with these “two things” –

((((have_weapon = "yes") and (weapon_health > 0)) and (stamina >= 10)) and (ultra_attack = "learned")) and (combat_type = "strongarm")

and while this alone would work fine after an *if, which can handle “two things,” for *selectable_if [1], the conditions all need to go inside a single final set of parentheses to become “one thing.”

(((((have_weapon = "yes") and (weapon_health > 0)) and (stamina >= 10)) and (ultra_attack = "learned")) and (combat_type = "strongarm"))

That big stack of parentheses at the beginning can be a helpful tool – start with as many as you have conditions that you’re checking (in this case, five), plus two parentheses at the end of each condition after the first, and that’ll boil a long list of conditions down to “one thing” as far as ChoiceScript is concerned.

But that approach can get hard to visually check once you’ve got more than four or five conditions. And it’s only sure to work if every condition is important in the same way, i.e. if they’re all linked with and (as in this example) or all linked with or. For a mix of ors and ands, you’ll need to understand the “no more than two things at a time principle,” and why it would work equally well to group your conditions into “one thing” this way:

((((have_weapon = "yes") and (weapon_health > 0)) and ((stamina >= 10) and (ultra_attack = "learned"))) and (combat_type = "strongarm"))

or this way:

((have_weapon = "yes") and (((weapon_health > 0) and (stamina >= 10)) and ((ultra_attack = "learned") and (combat_type = "strongarm"))))


  1. or multireplace, when you get there ↩︎

4 Likes

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