Is it possible... (making or/and statements with 3+ variables)

@ishantrissi is almost right. Try this instead :stuck_out_tongue:

*if (((var 1) or (var 2)) or ((var 3)))

1 Like

@samuel_h_young

I bow to your infinite(ly greater than mine) choicescript wisdom ^:)^

@ishantrissi
Hehe :slight_smile: CS is extremely picky when it comes to parenthesis.

@Kermit_Who, If the vars have to be numbers, then you can get by with one extra pair of parentheses on your original example:

*if ((var1 = 1) or (var2 = 1)) or (var3 = 1)

If they can be true/false (Booleans), then you can get by with even fewer parentheses, because in CS ‘*if var1=true’ can be shortened to ‘*if var1’. So to check if any of them are true, I believe this should work:

*if (var1 or var2) or var3

1 Like

@Havenstone
That’s good to know!

The key thing with logic statements like “or” and “and” is to give CS no more than 2 things to deal with at a time.

Anything in parentheses counts as one thing. So if you’ve got three things, tuck two of them in an extra parenthesis to turn them into one thing. That’s what I’ve done in the example above, turning two things

(var1 = 1) or (var2 = 1)

into one

((var1 = 1) or (var2 = 1))

If you wanted to take a fourth variable into account, just plop everything you’ve got so far inside another parenthesis to make it just one thing:

(((var1 = 1) or (var2 = 1)) or (var3 = 1))

and add your new second thing:

*if (((var1 = 1) or (var2 = 1)) or (var3 = 1)) or (var4 =1)

That should allow you to add as many “or” statements as you have time for.

7 Likes

@Havenstone
I frequently find myself using four and’s/or’s, so this is a great tip ^^

I have added it to http://www.choiceofbox.com/common-question/ for reference as I for get about it to lol.

Glad it’s handy. :slight_smile:

Since you mention and statements, it’s worth noting that they’re a little bit trickier, because the order matters. Don’t know if this example will be helpful to anyone at all, but here’s a stab:

If everything is an or, then each variable is equally important in the outcome. Imagine a game with some true/false variables that describe how our companion Dex has developed over the course of the story so far:

Will you vote for Dex as leader of the party?
*if (axe_murderer or bigot) or led_previous_party_to_deaths
  Your first impulse is to say OH HELL NO.

Because any of these “glaring massive flaw” variables would equally disqualify Dex if true, you link them using or, and you can shuffle those variables in any order you like:

*if (bigot or axe_murderer) or led_previous_party_to_deaths
*if (bigot or led_previous_party_to_deaths) or axe_murderer
*if (axe_murderer or led_previous_party_to_deaths) or bigot

all do the same thing. The only reason we’ve got parentheses in there is to help ChoiceScript follow what’s going on.

But maybe there’s an and involved. Sure, Dex led another party to their deaths last chapter, but it might have actually been someone else’s fault:

*set dex_fault false

So we only want the variable “led_previous_party_to_deaths” to come into play if “dex_fault” is true.

If we just add this and the way I described above for adding another or, though, it’ll cause problems:

*if ((bigot or axe_murderer) or led_previous_party_to_deaths) and dex_fault

will have us blithely voting for bigot Dex or axe-murderer Dex – as long as the deaths of the previous party weren’t Dex’s fault.

Instead, we need to structure our parentheses so that the two things linked by an and stay together as “one thing” logically – in this example, so “dex_fault” is a relevant qualifier if Dex got the party killed but not if Dex has become a bigot or murderous psychopath. Here are two different ways that should work, both in terms of the game logic and in terms of using parentheses to present ChoiceScript with one thing at a time:

*if (bigot or axe_murderer) or (led_previous_party_to_deaths and dex_fault)

*if ((led_previous_party_to_deaths and dex_fault) or bigot) or axe_murderer 

If we then want add more ands (you mentioned 4 mixed and/ors, Sam), we just need to make sure we keep the logic straight and add things one at a time, popping brackets around each new set of things we want to keep together.

Say for example that one of the protagonist stats is Softheartedness, and if you have a score above 75, you’ll be inclined to overlook little things like bigotry and Dex’s earlier fatally bad track record. (If Dex has become an axe murderer, even a softy still draws the line).

So we want to take our previous “one thing”

(led_previous_party_to_deaths and dex_fault)

and link it using an or to Dex’s bigotry – because we’d be willing to overlook either of these things if we’re soft enough –

((led_previous_party_to_deaths and dex_fault) or bigot)

then take account of the softheartedness threshold

(((led_previous_party_to_deaths and dex_fault) or bigot) and (softhearted < 76))

and finally bring the axe murdering back in.


Vote for Dex?
*if (((led_previous_party_to_deaths and dex_fault) or bigot) and (softhearted < 76)) or axe_murderer
    OH HELL NO.

Clear as mud? :slight_smile:

3 Likes

“*if (axe_murderer or bigot)”

LOLOLOLOL

@RascaldeesV2 – just for reference, you can do what you were aiming to with one fewer set of parentheses than you ended up with. Read this thread for detail.

Odd. I tried *if ((Delacruse >= 60) and (GenderValue = 1) and (Religion = 2) but it kept saying “error, expected close parenthesis”.

Unless you mean something else?

Try this:

*if (((Delacruse >= 60) and (GenderValue = 1)) and (Religion = 2))

1 Like

I think that’s what I currently have.

That’s not what you wrote above–you wrote
*if ((Delacruse >= 60) and (GenderValue = 1) and (Religion = 2)

1 Like

Yeah. Because Havenstone said I could do what I was aiming with less parentheses than I have. This is my code currently:

      *if (((Delacruse >= 60) and (GenderValue = 1)) and (Religion = 2))
       *goto DelacruseInterest
      *if (((Delacruse < 60) or (GenderValue != 1)) or (Religion != 2))
1 Like

I’d be interested to learn Havenstone’s technique, then! I always go fully armed with the full arsenal of parentheses!

I want to know too only because less characters used means less room for errors to occur. @Havenstone , can you weigh in when you have a moment?

CS is always looking to evaluate two conditions. So you need to use brackets to group up your conditions into pairs. Additional brackets for when you use an equals sign as part of your comparator.

All of these work. There’s other combinations, but this should cover all the main stuff.

*create Condition_1 true
*create Condition_2 true
*create Condition_3 true
*create Condition_11 10
*create Condition_22 10
*create Condition_33 10

*if (Condition_1 or Condition_2) or Condition_3
    Yes
    

*if (Condition_1 and Condition_2) and Condition_3
    Yes


*if ((Condition_1 = true) or (Condition_2 = true)) or (Condition_3 = true)
    Yes


*if ((Condition_11 = 10) or (Condition_22 = 10)) or (Condition_33 = 10)
    Yes
6 Likes

You’re missing the close-parenthesis for your first open-parenthesis. Try
*if ((Delacruse >= 60) and (GenderValue = 1)) and (Religion = 2)

The thread above explains that you need to give ChoiceScript no more than two things to chew on at the same time. Anything inside parentheses is one thing. So what you had ended up with on your thread

*if (((Delacruse >= 60) and (GenderValue = 1)) and (Religion = 2))

is all “one thing.” I was pointing out that you don’t need to keep Religion in a bracket with the other two. But you do need to make sure you keep Delacruse and GenderValue in the same bracket.

Everyone should do what works for them, obvs. :slight_smile: But I find the more parentheses there are, the harder it gets to parse. Not putting in unnecessary parentheses helps me keep track of what’s going on, especially if there are ors as well as ands in play.

3 Likes