Hi everyone!
This is my first time posting, and I was hoping my first topic would be something more exciting than “help I broke my game” but here we are.
So I have a scene written that chains together multiple if/elseif/if statements, like so…
*if (icecream = "yes")
You have ice cream
*if (toppings = "chocolatesyrup")
with chocolate syrup.
*goto beach
*elseif (toppings = "strayberrysyrup")
with strawberry syrup.
*goto beach
*else
with no toppings.
*goto beach
*else
You have no ice cream.
*goto icecream
(This is not my real code, in case anyone was wondering)
The problem is that whenever I quick/random test, I get an error saying that it is illegal to fall out of an if statement, and that I must goto or finish before the end of the indented block. I am confised because I thought that was what I had done. Do the *goto links in my nested if statements not count?
To make things even more confusing, I had playtested this part of the game previously, and everything seemed to work fine there…it was just quicktest that was erroring out.
Any help would be hugely appreciated! Thank you!!!
I would go this route
*if (icecream = "yes")
You have ice cream
*if (toppings = "chocolatesyrup")
with chocolate syrup.
*goto beach
*if (toppings = "strayberrysyrup")
with strawberry syrup.
*goto beach
*if (toppings = "")
with no toppings.
*goto beach
*else
You have no ice cream.
*goto icecream
Edit missed what you where going for until the code was indented so change my code to reflect.
Thank you, I will try this! (Right now I just have a ridiculously long chain of gotos to get around the error)
If there is a way to do this with the elseif/else parts though, I would love to hear about it because that may be useful in the future
There are many way to handle the code but with out seeing it hard to say. Early on I used if/elseif/else but just using if/else is ok as well as it is more of how you want to look at the code. There are often shorter code you can use but again need to understand what you want it to do before any suggestions can be offered. 
When you’re posting code to the forum, if you highlight it and click the “</>” button it’ll show as code
*if clicked
like this
That will help us see how you’ve indented your code, which is essential for figuring out where it’s going wrong… Just took the liberty of doing it for you.
3 Likes
Ah thank you I was wondering how people do that!
Basically I’m trying to figure out a way to have nested if/elseif statements. I will find and post another one from my actual code if I can.
I have like three levels of ‘if’ sometimes in my game to adjust for variable characters, and it is very easy to loose track of everything. I tend to write the base code first before filling in the text, that way it becomes easier to spot errors. That and color coding. Sometimes I have to shift everything into another document and color everything so I can see how the choices flow.
Take for example the recent kissing flowchart I am working on, where’s there a lot of 'if’s nesting, since I have to adjust for the NPC*s (Ortega’s) gender, the MC’s gender, and the height of the body (the puppet) the MC is currently inhabiting to figure out some details about the kiss. I usually never bother with elseifs, normal ifs work just fine, and it makes the code easier for me to decipher.
*if ortega_gender = "man"
*if puppet_height = "tall"
*goto tallkiss
*else
*if gender = "male"
*goto samekiss
*else
*goto tallkiss
*else
*if puppet_gender = "man"
*if puppet_height = "tall"
*goto tallkiss
*else
*if gender = "male"
*goto samekiss
*else
*goto tallkiss
*else
*if puppet_height = "tall"
*if gender = "male"
*goto samekiss
*else
*goto tallkiss
*else
*if gender = "male"
*goto shortkiss
*else
*goto samekiss
1 Like
@cabinpersephone, What you’re doing should work fine – if you post the actual code from where the game is crashing, we should be able to tell where the problem is.
2 Likes
So I went to put the code back the way it was before I “fixed” it so I could show everyone, and realized that I was using elseifs without elses. So I fixed it and lo and behold, I passed quicktest!
So it turns out the error was not what I thought it was at all (I’m a little confused because the error message I got definitely told me that I needed to *goto or *finish before the end of the indented text) but it’s fixed nevertheless!
Thank you everyone for your advice (I think I’ll just dispense with elseifs wherever possible in the future) and for helping me figure out what the problem was!!!
2 Likes