If <condition> else and elseif help


#1

`

*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…


#2

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.


#3

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.


#4

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.


#5

@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


#6

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 :wink:

so this does work…

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


#7

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!


#8

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


#9

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:

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

Correct indentation is covered here:


#10

Works, thanks


#11

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?


#12
*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).


#13

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


#14

@WiredChimpanzee, good luck with that :slight_smile:


#15

Thanks