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


#1

Is there any way to make a statement that would do what this would do:

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

I know this doesn’t work, but is there any way something like this could be achieved?


Help with a complex exclusion
Some question about states and states check
Problem with using Variable Stat Titles
How to do multiple ifs at the same time
#2

@kermit_who

try putting it like this…

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

might work in theory, haven’t tried it out yet


#3

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

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


#4

@samuel_h_young

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


#5

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


#6

@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


#7

@Havenstone
That’s good to know!


#8

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.


If with three ors
Multiple "Ands"
I need more than AND (Solved)
Help with concatenation?
Multiple *or statement
IF code and multiple var
Choicescript help (if and variables)
Question regarding [and] [or] operators
#9

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


#10

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


#11

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:


Parenthesis check. Having a random brain day (Solved)
Making text visible if multiple conditions are true
Question regarding [and] [or] operators
#12

“*if (axe_murderer or bigot)”

LOLOLOLOL