# Choicescript help (if and variables)

**URL:** <https://forum.choiceofgames.com/t/choicescript-help-if-and-variables/34734>\
**Category:** ChoiceScript Help\
**Created:** [January 27, 2018, 2:23pm UTC](https://forum.choiceofgames.com/t/choicescript-help-if-and-variables/34734 "2018-01-27T14:23:07Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![SmolPirate](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/smolpirate/32/44865_2.png) [@SmolPirate](https://forum.choiceofgames.com/u/SmolPirate)\
**Post date:** [January 27, 2018, 2:23pm UTC](https://forum.choiceofgames.com/t/choicescript-help-if-and-variables/34734/1 "2018-01-27T14:23:07Z")

</div>

Need help with some coding.  
This is what i have:

```
*if ((((Gender = "Male") or (Gender = "Female")) and (((background = "suburbs") and ((kind > funny) or (kind > mean))))

```

This is my error:

“Invalid expression, expected CLOSE\_PARENTHESIS”

---

<div class="post-metadata">

**Author:** ![Gower](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/gower/32/21972_2.png) [@Gower](https://forum.choiceofgames.com/u/Gower)\
**Post date:** [January 27, 2018, 2:27pm UTC](https://forum.choiceofgames.com/t/choicescript-help-if-and-variables/34734/2 "2018-01-27T14:27:06Z")

</div>

Try

\*if (((blah) and (blah2)) and (blah3))

---

<div class="post-metadata">

**Author:** ![SmolPirate](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/smolpirate/32/44865_2.png) [@SmolPirate](https://forum.choiceofgames.com/u/SmolPirate)\
**Post date:** [January 27, 2018, 2:28pm UTC](https://forum.choiceofgames.com/t/choicescript-help-if-and-variables/34734/3 "2018-01-27T14:28:59Z")

</div>

> [@Gower](#):
>
> Try
> 
> \*if (((blah) and (blah2)) and (blah3))

Thanks for the quick response 🙂  
But would that work with “or” as well?

---

<div class="post-metadata">

**Author:** ![Gower](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/gower/32/21972_2.png) [@Gower](https://forum.choiceofgames.com/u/Gower)\
**Post date:** [January 27, 2018, 2:29pm UTC](https://forum.choiceofgames.com/t/choicescript-help-if-and-variables/34734/4 "2018-01-27T14:29:53Z")

</div>

Yes, that should work with or as well.

---

<div class="post-metadata">

**Author:** ![SmolPirate](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/smolpirate/32/44865_2.png) [@SmolPirate](https://forum.choiceofgames.com/u/SmolPirate)\
**Post date:** [January 27, 2018, 2:34pm UTC](https://forum.choiceofgames.com/t/choicescript-help-if-and-variables/34734/5 "2018-01-27T14:34:34Z")

</div>

> [@Gower](#):
>
> Yes, that should work with or as well.

I tried it:

```choicescript
*if (((Gender = "Male") or (Gender = "Female")) and (background = "suburbs") and (kind > funny) or (kind > mean))

```

and i got this:

“Invalid expression at char 76, expected CLOSE\_PARENTHESIS, was: NAMED\_OPERATOR [and]”

---

<div class="post-metadata">

**Author:** ![iMadeYouReadThis](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/imadeyoureadthis/32/8012_2.png) [@iMadeYouReadThis](https://forum.choiceofgames.com/u/iMadeYouReadThis)\
**Post date:** [January 27, 2018, 2:37pm UTC](https://forum.choiceofgames.com/t/choicescript-help-if-and-variables/34734/6 "2018-01-27T14:37:19Z")

</div>

Try:

\*if((Gender=“Male”) or ((Gender=“Female”) and (background=“suburbs”)) and ((kind \> funny) or (kind\>mean)))

---

<div class="post-metadata">

**Author:** ![Gower](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/gower/32/21972_2.png) [@Gower](https://forum.choiceofgames.com/u/Gower)\
**Post date:** [January 27, 2018, 2:38pm UTC](https://forum.choiceofgames.com/t/choicescript-help-if-and-variables/34734/7 "2018-01-27T14:38:17Z")

</div>

Right, with four variables it’s a bit different–takes some getting used to! I do my best to avoid four, actually, because the parenthesis get nutty.

---

<div class="post-metadata">

**Author:** ![SmolPirate](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/smolpirate/32/44865_2.png) [@SmolPirate](https://forum.choiceofgames.com/u/SmolPirate)\
**Post date:** [January 27, 2018, 2:41pm UTC](https://forum.choiceofgames.com/t/choicescript-help-if-and-variables/34734/8 "2018-01-27T14:41:51Z")

</div>

> [@iMadeYouReadThis](#):
>
> Try:
> 
> \*if((Gender=“Male”) or ((Gender=“Female”) and (background=“suburbs”)) and ((kind \> funny) or (kind\>mean)))

Thanks for helping out too 😃

I did as you said:

```choicescript
*if ((Gender = "Male") or ((Gender = "Female") and (background = "suburbs")) and ((kind > funny or kind > mean)))

```

I got the same error:

“Invalid expression at char 76, expected CLOSE\_PARENTHESIS, was: NAMED\_OPERATOR [and]”

---

<div class="post-metadata">

**Author:** ![SmolPirate](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/smolpirate/32/44865_2.png) [@SmolPirate](https://forum.choiceofgames.com/u/SmolPirate)\
**Post date:** [January 27, 2018, 2:43pm UTC](https://forum.choiceofgames.com/t/choicescript-help-if-and-variables/34734/9 "2018-01-27T14:43:03Z")

</div>

> [@Gower](#):
>
> Right, with four variables it’s a bit different–takes some getting used to! I do my best to avoid four, actually, because the parenthesis get nutty.

I know, but i have no idea how to do make it easier. I’m kind of new to this too.

I got the first right:

```choicescript
*if (((Gender = "Male") and (background = "village")) and ((mean > kind) or (mean > funny)))

```

I don’t think it gave me an error…

---

<div class="post-metadata">

**Author:** ![iMadeYouReadThis](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/imadeyoureadthis/32/8012_2.png) [@iMadeYouReadThis](https://forum.choiceofgames.com/u/iMadeYouReadThis)\
**Post date:** [January 27, 2018, 2:46pm UTC](https://forum.choiceofgames.com/t/choicescript-help-if-and-variables/34734/10 "2018-01-27T14:46:11Z")

</div>

I forgot “(” and “)” in a few places, edited it just now, sorry, I’m on the phone so it’s tricky to write a code 😅

---

<div class="post-metadata">

**Author:** ![SmolPirate](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/smolpirate/32/44865_2.png) [@SmolPirate](https://forum.choiceofgames.com/u/SmolPirate)\
**Post date:** [January 27, 2018, 2:50pm UTC](https://forum.choiceofgames.com/t/choicescript-help-if-and-variables/34734/11 "2018-01-27T14:50:35Z")

</div>

> [@iMadeYouReadThis](#):
>
> I forgot “(” and “)” in a few places, edited it just now, sorry, I’m on the phone so it’s tricky to write a code 😅

No worries friend! I appreciate the help you’re giving.

The coding is like this now:

```choicescript
*if ((Gender = "Male") or ((Gender = "Female") and (background = "suburbs")) and ((kind > funny) or (kind > mean)))

```

And it seems i got the same error:

“Invalid expression at char 76, expected CLOSE\_PARENTHESIS, was: NAMED\_OPERATOR [and”

☹

---

<div class="post-metadata">

**Author:** ![Retrovirus](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/retrovirus/32/43354_2.png) [@Retrovirus](https://forum.choiceofgames.com/u/Retrovirus)\
**Post date:** [January 27, 2018, 2:51pm UTC](https://forum.choiceofgames.com/t/choicescript-help-if-and-variables/34734/12 "2018-01-27T14:51:44Z")

</div>

Does this work?  
\*if (((Gender = “Male”) or (Gender = “Female”)) and (background = “suburbs”)) and ((kind \> funny) or (kind \> mean))

Otherwise, it really depends on what exactly are the units you’re using. For future reference, though, it can only handle two units at a time so what I like to do is bracket off the “or” parts first and combine them into one unit each, and then start bracketing the “and” statements together.

---

<div class="post-metadata">

**Author:** ![SmolPirate](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/smolpirate/32/44865_2.png) [@SmolPirate](https://forum.choiceofgames.com/u/SmolPirate)\
**Post date:** [January 27, 2018, 2:57pm UTC](https://forum.choiceofgames.com/t/choicescript-help-if-and-variables/34734/13 "2018-01-27T14:57:02Z")

</div>

> [@Retrovirus](#):
>
> Does this work?
> 
> \*if (((Gender = “Male”) or (Gender = “Female”)) and (background = “suburbs”)) and ((kind \> funny) or (kind \> mean))
> 
> Otherwise, it really depends on what exactly are the units you’re using. For future reference, though, it can only handle two units at a time so what I like to do is bracket off the “or” parts first and combine them into one unit each, and then start bracketing the “and” statements together.

IT WORKED! Thank you so much! \<3  
I would hug you if i could!

Maaan, i love this community… 😄

---

<div class="post-metadata">

**Author:** ![Havenstone](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/havenstone/32/198451_2.png) [@Havenstone](https://forum.choiceofgames.com/u/Havenstone)\
**Post date:** [January 28, 2018, 2:31am UTC](https://forum.choiceofgames.com/t/choicescript-help-if-and-variables/34734/14 "2018-01-28T02:31:04Z")

</div>

> [@Is it possible... (making or/and statements with 3+ variables)](https://forum.choiceofgames.com/t/is-it-possible-making-or-and-statements-with-3-variables/2411/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](https://forum.choiceofgames.com/t/is-it-possible-making-or-and-statements-with-3-variables/2411/6), 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 p…

Hope this helps. Read down for an example combining ands with ors…

---

<div class="post-metadata">

**Author:** ![SmolPirate](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/smolpirate/32/44865_2.png) [@SmolPirate](https://forum.choiceofgames.com/u/SmolPirate)\
**Post date:** [January 28, 2018, 9:45am UTC](https://forum.choiceofgames.com/t/choicescript-help-if-and-variables/34734/15 "2018-01-28T09:45:42Z")

</div>

> [@Havenstone](#):
>
> Is it possible… (making or/and statements with 3+ variables)
> 
> 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 anot…
> 
> Hope this helps. Read down for an example combining ands with ors…

Thank you so much for the reply, though I’ve already solved it thanks to some amazing people.  
But thank you really for the explanation, I understand this better now!
