# If \<condition\> else and elseif help

**URL:** <https://forum.choiceofgames.com/t/if-condition-else-and-elseif-help/711>\
**Category:** ChoiceScript Help\
**Created:** [August 28, 2012, 10:02am UTC](https://forum.choiceofgames.com/t/if-condition-else-and-elseif-help/711 "2012-08-28T10:02:06Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pace675](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/pace675/32/10543_2.png) [@Pace675](https://forum.choiceofgames.com/u/Pace675)\
**Post date:** [August 28, 2012, 10:02am UTC](https://forum.choiceofgames.com/t/if-condition-else-and-elseif-help/711/1 "2012-08-28T10:02:06Z")

</div>

`

\*create gender  
\*create sex  
\*set sex 0  
\*create himher  
\*create heshe

\*goto zero  
\*label zero

Insert wall o’ text leading to a choice

\*choice  
#Girl  
\*set gender “Female”  
\*set sex 1  
\*goto one  
#Boy  
\*set gender “Male”  
\*set sex 2  
\*goto one

\*label one

{gender} {sex} (just seeing that they do get set and they do!)

\*if gender =“Female”  
\*set himher “her”  
\*set heshe “she”  
\*goto two  
\*else  
\*set himher =“him”  
\*set heshe =“he”  
\*goto two

\*label two

{heshe} was the cat's meow, and {himher} cat loved to follow ${himher} around!  
\*finish

`

Now here is the crux of the problem, the girl option always will work. But if you select boy you will get an error “Varible heshe exsits but is not defined”

I even tried this route with \*label one

`

\*if gender =“Female”  
\*if sex =1  
\*set himher “her”  
\*set heshe “she”  
\*goto second  
\*elseif sex =2  
\*set himher “him”  
\*set heshe “he”  
\*goto second  
`

Same error. Maybe I am looking at the problem the wrong way…

---

<div class="post-metadata">

**Author:** ![JimD](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/jimd/32/21672_2.png) [@JimD](https://forum.choiceofgames.com/u/JimD)\
**Post date:** [August 28, 2012, 10:06am UTC](https://forum.choiceofgames.com/t/if-condition-else-and-elseif-help/711/2 "2012-08-28T10:06:53Z")

</div>

Don’t use \*create. If you want a global variable (one that saves between scenes), declare it in mygame.js.

,gender: female

If you want a local (scene only) variable, use temp and set.  
\*temp heshe  
\*set heshe “she”

In these two methods, the variables are created and declared.

---

<div class="post-metadata">

**Author:** ![Pace675](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/pace675/32/10543_2.png) [@Pace675](https://forum.choiceofgames.com/u/Pace675)\
**Post date:** [August 28, 2012, 10:31am UTC](https://forum.choiceofgames.com/t/if-condition-else-and-elseif-help/711/3 "2012-08-28T10:31:39Z")

</div>

I’ll try it that way, and thanks for the quick responce @JimD

But it is quite odd that it works fine with choice 1 but with the second choice is gets grumpy.

Made gender a global and temp the other

\*label one

{gender} {sex} (just seeing that they do get set)  
\*temp himher  
\*set himher “unknow”  
\*temp heshe  
\*set heshe “unknown”

\*if gender =“Female”  
\*set himher “her”  
\*set heshe “she”  
\*goto two  
\*else  
\*set himher =“him”  
\*set heshe =“he”  
\*goto two

still gives the same error and the first choice still works properly.

---

<div class="post-metadata">

**Author:** ![Pace675](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/pace675/32/10543_2.png) [@Pace675](https://forum.choiceofgames.com/u/Pace675)\
**Post date:** [August 28, 2012, 12:12pm UTC](https://forum.choiceofgames.com/t/if-condition-else-and-elseif-help/711/4 "2012-08-28T12:12:36Z")

</div>

Actuall a slight correction to the above problem…choice one works as intened but choice 2 will give “unknown” as an answer. So it looks like the code is ignoring the else and else if statement.

---

<div class="post-metadata">

**Author:** ![Nocturnal\_Stillness](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/nocturnal_stillness/32/100414_2.png) [@Nocturnal\_Stillness](https://forum.choiceofgames.com/u/Nocturnal_Stillness)\
**Post date:** [August 28, 2012, 1:19pm UTC](https://forum.choiceofgames.com/t/if-condition-else-and-elseif-help/711/5 "2012-08-28T13:19:52Z")

</div>

@Pace675

Put himher and heshe in mygame.js as you’ll probably use them often.

As for the error try this (for the coding issue in the forum \_ = a space)

\*choice  
\_\_#boy  
\_\_\_\_\*set gender “Male”  
\_\_\_\_\*set himher “him”  
\_\_\_\_\*set heshe “he”  
\_\_\_\_\*goto two

\_\_#girl  
\_\_\_\_\*set gender “Female”  
\_\_\_\_\*set himher “her”  
\_\_\_\_\*set heshe “she”  
\_\_\_\_\*goto two

---

<div class="post-metadata">

**Author:** ![Pace675](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/pace675/32/10543_2.png) [@Pace675](https://forum.choiceofgames.com/u/Pace675)\
**Post date:** [August 28, 2012, 2:00pm UTC](https://forum.choiceofgames.com/t/if-condition-else-and-elseif-help/711/6 "2012-08-28T14:00:09Z")

</div>

Actually that is the way I first tried, but it is now working (boy CS is a cranky thing to get working). I also know about the spacing issues even using code tags it doesn’t keep the spacing \>\<.

added himher ect to mygame.js and that seemed to fix the problem. Which has me scratching my head using temps should have worked \>.\<

Again thanks guys now my crisis is over I can go back to my feeble attempt at coding 😉

so this does work…

` *if gender ="Female" *set himher "her" *set heshe "she" *goto two *else *set himher "him" *set heshe "he" *goto two`

---

<div class="post-metadata">

**Author:** ![Radontemporum](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/radontemporum/32/499_2.png) [@Radontemporum](https://forum.choiceofgames.com/u/Radontemporum)\
**Post date:** [October 13, 2012, 4:27am UTC](https://forum.choiceofgames.com/t/if-condition-else-and-elseif-help/711/7 "2012-10-13T04:27:04Z")

</div>

I’m having problems with if statements.  
The following doesn’t seem to work.  
\*label story  
“So, what’s your story?” She asks.  
\*line\_break  
“Well…” You start.  
\*page\_break Tell story  
You awake in your bed. You look around in a slight daze then remember that your final exam is today! You get up, wash yourself and get dressed. You go to your bag and  
pull out your revision guide.  
\*page\_break  
\*if (aclass=warrior)  
\*goto warrev  
\*elseif (aclass=mage)  
\*goto magrev  
\*elseif (aclass=assassin)  
\*goto assrev  
\*else  
\*goto ranrev  
Help!

---

<div class="post-metadata">

**Author:** ![Radontemporum](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/radontemporum/32/499_2.png) [@Radontemporum](https://forum.choiceofgames.com/u/Radontemporum)\
**Post date:** [October 13, 2012, 4:29am UTC](https://forum.choiceofgames.com/t/if-condition-else-and-elseif-help/711/8 "2012-10-13T04:29:34Z")

</div>

Update: -=space  
\*label story  
“So, what’s your story?” She asks.  
\*line\_break  
“Well…” You start.  
\*page\_break Tell story  
You awake in your bed. You look around in a slight daze then remember that your final exam is today! You get up, wash yourself and get dressed. You go to your bag and  
pull out your revision guide.  
\*page\_break  
-\*if (aclass=warrior)  
—\*goto warrev  
–\*elseif (aclass=mage)  
—\*goto magrev  
–\*elseif (aclass=assassin)  
—\*goto assrev  
–\*else  
—\*goto ranrev

---

<div class="post-metadata">

**Author:** ![Vendetta](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/vendetta/32/533_2.png) [@Vendetta](https://forum.choiceofgames.com/u/Vendetta)\
**Post date:** [October 13, 2012, 4:38am UTC](https://forum.choiceofgames.com/t/if-condition-else-and-elseif-help/711/9 "2012-10-13T04:38:26Z")

</div>

It should look like this, as **aclass** is a _string_ variable so its contents must always be referenced using “quote marks”. Note also the slight difference in indentation - \*elseif and \*else go on the same level as \*if, which is not itself indented in this case as the previous command is only \*page\_break, not something requiring that the following line be indented farther.

```

*page_break 
*if (aclass = "warrior") 
  *goto warrev 
*elseif (aclass = "mage") 
  *goto magrev 
*elseif (aclass = "assassin") 
  *goto assrev 
*else 
  *goto ranrev 

```

It’s worth studying the three different data types:

> **[Data types](https://choicescriptdev.fandom.com/wiki/Data_types)**
>
> This article is aimed at beginners to ChoiceScript. However, if you have not already done so then the best place to start would be with the very first article in this Introduction To ChoiceScript Game Development series of linked articles: A Basic...

And how to properly define each of these in mygame.js to prevent loading issues:

> **[Mygame.js](https://choicescriptdev.fandom.com/wiki/Mygame.js)**
>
> This article is aimed at beginners to ChoiceScript. However, if you have not already done so then the best place to start would be with the very first article in this Introduction To ChoiceScript Game Development series of linked articles: A Basic...

Correct indentation is covered here:

> **[Indentation](https://choicescriptdev.fandom.com/wiki/Indentation)**
>
> This article is aimed at beginners to ChoiceScript. However, if you have not already done so then the best place to start would be with the very first article in this Introduction To ChoiceScript Game Development series of linked articles: A Basic...

---

<div class="post-metadata">

**Author:** ![Radontemporum](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/radontemporum/32/499_2.png) [@Radontemporum](https://forum.choiceofgames.com/u/Radontemporum)\
**Post date:** [October 13, 2012, 4:50am UTC](https://forum.choiceofgames.com/t/if-condition-else-and-elseif-help/711/10 "2012-10-13T04:50:53Z")

</div>

Works, thanks

---

<div class="post-metadata">

**Author:** ![WiReDcHiMpAnZeE](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/wiredchimpanzee/32/6927_2.png) [@WiReDcHiMpAnZeE](https://forum.choiceofgames.com/u/WiReDcHiMpAnZeE)\
**Post date:** [November 28, 2012, 6:28pm UTC](https://forum.choiceofgames.com/t/if-condition-else-and-elseif-help/711/11 "2012-11-28T18:28:36Z")

</div>

I would like to make a part in a script where you go a certain place depending on which variable has the most “points”, would it be possible to do this:  
\*If var1\> var2, var3, var4, var5  
\*goto\_scene brahmin  
\*elseif var2\< var1, var3, var4, var5  
\*goto\_scene kshatriya  
\*else if var3\< var1, var2, var4, var5  
\*goto\_scene vaishya  
\*elseif var4\< var1, var2, var3, var5  
\*goto\_scene sudra  
\*else  
\*goto\_scene untouchables

Also if not what would work best?

---

<div class="post-metadata">

**Author:** ![AlexCosarca](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/alexcosarca/32/68977_2.png) [@AlexCosarca](https://forum.choiceofgames.com/u/AlexCosarca)\
**Post date:** [November 28, 2012, 6:32pm UTC](https://forum.choiceofgames.com/t/if-condition-else-and-elseif-help/711/12 "2012-11-28T18:32:50Z")

</div>

```
*if (((var1 > var2) and (var1 > var3)) and ((var1 > var4) and (var1 > var5)))

```

This is how you’d do the conditions (you must use parantheses so between each pair of parantheses you have a maximum of two conditions; note the last pair of parantheses isn’t neccessary).

---

<div class="post-metadata">

**Author:** ![WiReDcHiMpAnZeE](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/wiredchimpanzee/32/6927_2.png) [@WiReDcHiMpAnZeE](https://forum.choiceofgames.com/u/WiReDcHiMpAnZeE)\
**Post date:** [November 28, 2012, 6:34pm UTC](https://forum.choiceofgames.com/t/if-condition-else-and-elseif-help/711/13 "2012-11-28T18:34:40Z")

</div>

Ok thanks, im helping my world cultures teacher by making a test for him

---

<div class="post-metadata">

**Author:** ![AlexCosarca](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/alexcosarca/32/68977_2.png) [@AlexCosarca](https://forum.choiceofgames.com/u/AlexCosarca)\
**Post date:** [November 28, 2012, 6:36pm UTC](https://forum.choiceofgames.com/t/if-condition-else-and-elseif-help/711/14 "2012-11-28T18:36:35Z")

</div>

@WiredChimpanzee, good luck with that 🙂

---

<div class="post-metadata">

**Author:** ![WiReDcHiMpAnZeE](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/wiredchimpanzee/32/6927_2.png) [@WiReDcHiMpAnZeE](https://forum.choiceofgames.com/u/WiReDcHiMpAnZeE)\
**Post date:** [November 28, 2012, 6:37pm UTC](https://forum.choiceofgames.com/t/if-condition-else-and-elseif-help/711/15 "2012-11-28T18:37:16Z")

</div>

Thanks
