Question regarding [and] [or] operators


#1

Hello everyone!

I have a quick question about using ‘or’/‘and’ command for *if statements. I’ve provided the choicescript guide pages which addresses these commands below:

And/or/not (with mandatory parentheses)
And: (leadership > 30) and (strength > 40)
Or: (leadership > 60) or (strength > 70)
Not: not(strength > 70)
Complex parentheses: ((leadership > 60) and (agility > 20)) or (strength > 80)

The bolded ones are the ones I’m interested in currently. I was wondering if it’s possible to put more than one ‘and’ or put more than one ‘or’ operator in the same line of code for an *if statement to be available.

For example, can I do something like this?

Example 1
*if (weapon = 1) or (weapon = 3) or (weapon = 5)
   #Use this weapon
*elseif (weapon = 4)
   #Throw this weapon
*else
   #Flail

Example 2
*if (p1met = false) and (p2met = false) and (p3met = false)
   Description of three NPCs not previously met
   *goto nextscene
*else
   *goto nextscene

The examples basically show there are more than two possible conditions that will result in the same option. Or do I have to do it two at a time, even if the option is the same?

Please let me know if my question isn’t clear or if I need to explain further. Thank you!

Edit: I’m still looking through the forums for any previous posts about this topic. I haven’t found any yet, but if you know of one, please point me in the right direction, thanks!


#2

Yes, you can, but you’ll have to layer parentheses every time you add another condition.
This works:

*if (((var1 > 10) and (var2 > 20)) and (var3 > 30))

This doesn’t:

*if ((var1 > 10) and (var2 > 20) and (var3 > 30))

(From the ChoiceScript Wiki article on *if)


#3

Okay, I saw the bit about the complex parentheses, and I was wondering if that could work with the same type of operator.

I’m glad to know it works! Thank you very much! I’ll be trying that out, and I assume it’ll work for 3+ commands as well? If it does, would the code be something like this?

*if (((w = 1) or (w = 2)) or ((w = 3) or (w = 4)) or ((w = 5) or (w =6)))

You place parentheses for pairs and the last would be a single if it is uneven, or paired if an even number of variables come into play?


#4

I’m a little confused by it myself; I believe choicescript can only process two conditions at a time, so they have to be paired. Here’s code that I wrote that worked (not sure if ‘or’ instead of ‘and’ will change things):

*if (((((sympathy > 50) and (sympathy > discipline)) and (sympathy > independence)) and (sympathy > caution)) and (sympathy > bravado))

Basically, every time I added on another condition, I put another set of parentheses around everything


#5

Okay, I see what you mean by grouping everything together with each addition.

I’ll definitely try it out. Thank you for the help!


#6

@Alexandra’s right, ChoiceScript processes variables by pairs. I tend to code them this way, which helps me to make sure I have the parenthesis in the right place—especially if I’m mixing ands and ors, like this:

*if ((((wisdom > 65) and (fable > 65)) or ((strength > 65) and (determination > 65))) or ((devices > 75) and (study > 65)))

(That could all be done with only and for a super-stats choice, too, instead of having or as well.)

That may be more parentheses than I strictly need, I think, but at least I’m sure about what goes with which. Plus I code in CSIDE, which highlights matching parenthetical sets for me. I’ve found that to be super helpful.


#7

Just for reference, here are two previous posts from way back when on this topic.

The summary version: you’ve got to (a) give ChoiceScript no more than two things to deal with at a time, and (b) if using a combination of “and” and “or” statements, remember that order matters and take care to group the things that logically need grouping.


#8

Well, (b) is true in any language, just more explicitly obvious because of (a) in the case of CS. I mean, how does a non-coder parse: if ( foo == true && bar !== "false" || foobar >= 10) {} ?


#9

In my case? Blinking, trying again, and total failure.


#10

@Fiogan Yes, thank you for the example! Notepad thankfully has the feature of highlighting parentheses too now, so I can check if they’re properly paired. It’s certainly more complex, but now that I know CS works with pairs, it’s a lot easier to handle.

@Havenstone Thank you very much! I guess I should have hunted around a little bit further.

So far, it’s worked, but if not, I’ll definitely be referencing back to this thread and the two others you posted for help.


#11

I figured out my previous question, but I have another.

I’m hunting through the forums for as I type this. So I may change this later if I find my answer.

Can you put multiple not() statements in an *if statement with the [or] [and] operators?


#12

Yes?


*if not ((five = 5) and (hablahablah))

Is acceptable.


I think this is also acceptable

*if ((not (true) or (five = 5))

#13

Thank you, I just tried the first version and it worked. I was trying to put more than one "not()"s in the phrase, rather than lumping it all into one not().


#14

Well, I’d recommend against using multiple not() tho :/
Can be hard to track and debug


#15

So it seems. I only happened to notice it because the scene wasn’t playing out according to the weapon used. If I hadn’t, I doubt I would have noticed it at all.

Thank you again! I definitely will stick to grouping it together in future.


#16

Another way to parse it is using !=, which is basically ‘does not equal’, and = false for booleans. So you’d have something like:


*temp five 50
*temp heffalump false
*temp woozles "where are the woozles"

*if (((five != 5) and (heffalumps = false)) and ((woozles != "here")))
    We're all right for now!
    *goto onwards_friends