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?
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?
try putting it like this…
*if (((var1 = 1) or (var2 = 1) or (var3 = 1)))
might work in theory, haven’t tried it out yet
@ishantrissi is almost right. Try this instead
*if (((var 1) or (var 2)) or ((var 3)))
I bow to your infinite(ly greater than mine) choicescript wisdom ^:)^
@ishantrissi
Hehe 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
@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.
@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.
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?
“*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))
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)
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))
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?