Issue with if/elif/else statements (Expected statement error) // SOLVED

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
jingleriot
Regular
Posts: 25
Joined: Mon Sep 05, 2016 7:53 pm
Projects: Ventio Mortis, Sector Chimera, Monster Party
Deviantart: jingleriot
itch: https://jingleriotga
Contact:

Issue with if/elif/else statements (Expected statement error) // SOLVED

#1 Post by jingleriot »

I'm having a weird problem with my code. I've scoured the internet for answers, but none of the solutions have helped so far.

Here is the error:

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/nzone.rpy", line 104: end of line expected.
    elif cbog is "2":
                    ^

File "game/nzone.rpy", line 134: end of line expected.
    elif cbog is "3":
                    ^

File "game/nzone.rpy", line 192: end of line expected.
    elif cbog is "4":
                    ^

File "game/nzone.rpy", line 202: expected statement.
    else:
        ^

Ren'Py Version: Ren'Py 6.99.13.2919
And here is the code. An important side note: this is a separate rpy from the script, if that might have anything to do with it. I've also deleted a bunch of dialog from the code to condense it here so the main problem can be focused on more easily.

Code: Select all

label crystalbog:
    
    if cbog is "1":
        "[You walk for a while until you reach the edge of a bog. The crystals hum quietly, blending into the sound of the running water. A girl stands in the distance, until she notices youand your companions.]"
        x "Hey!! Can you help me?"
        menu:
            "Yes, I'll help.":
                x "Thank you!"
            "What's in it for me?":
                x "I... don't have anything."
                menu:
                    "Alright, fine.":
                        ruby "You're too damn soft, [mc]."
                    "Anything at all?":
                        x "You won't just help me? I can try to scrounge up something!"
                    "No deal.":
                        x "Fine... I'll figure it out myself, then."
                    
            "No, sorry.":
                x "Fine... I'll figure it out myself, then."
            "Nooooope.":
                x "Fine... I'll figure it out myself, then."
            
        rh "Alright. Okay. Fine. We'll help you."
        jump battle_game_3
    label bogcont:
        x "Stop!"
        menu:
            "I want to talk to that boy.":
                x "Children hide behind safe pillars, away from a stranger's prying eyes. And yet, you appear to lay them on him all the same, no?"
                ruby "Oh, come on, lady. You know what they meant."
                rh "Ah, a clever kere. That's just what we need."
                if pgen = True:
                    gen "And what a sight to behold, however, can we have the kid or not?"
                    lady "I see..."
                else:
                    lady "I see..."
                lady "A quest to be completed, but it is never a simple task."
                lady "A challenger must accept the changes. Four unawnsered questions remain. Then you may have your boon. More useful than children, or perhaps it was more useful to children..."
                rh "We realy don't have time for silly games."
                if pats = True:
                    ats "Oooo, I love a good brain teaser~"
                    lady "Answer the questions with gifts and I will answer your questions with gifts. Yes?"
                else:
                    lady "Answer the questions with gifts and I will answer your questions with gifts. Yes?"
                menu:
                    "Yes (Begin 'Hidden Meaning')":
                        lady "As I've said, four questions remain. When all the answers have been found, return them to me."
                        ruby "Say it in laymen's terms, lady."
                        rh "Yes, please just say it plainly."
                        if pats = True:
                            ats "I'm starting to get a headache... maybe brain teasers aren't that fun after all."
                        else:
                            pass
                        lady "Should you be successful, I will not only give you the boy, but wisdom as well."
                        if pcal = True:
                            cal "I'm predicting corn in our future. Weird."
                        else:
                            pass
                        lady "I wish you luck."
                        $ cbog = 3
                        
                        
                    "No": 
                        lady "A child is lost, but is it him?"
                        lady "I will be here when the child wishes to find their way once more."
                        $ cbog = 2
                        
            "May I pass?":
                lady "It seems you can, and yet you cannot."
                $ cbog = 2
                
            "Get out of my way.":
                lady "The wind blows, but the tree stands firm."
                $ cbog = 2
        jump night1
                
    elif cbog is "2":
        lady "Have you returned with a changed mind?"
        menu:
            "Yes (Begin 'Hidden Meaning')":
                lady "As I've said, four questions remain. When all the answers have been found, return them to me."
                if pats = True:
                    ats "I'm starting to get a headache... maybe brain teasers aren't that fun after all."
                else:
                    pass
                lady "Should you be successful, I will not only give you the boy, but wisdom as well."
                if pcal = True:
                    cal "I'm predicting corn in our future. Weird."
                else:
                    pass
                lady "I wish you luck."
                $ cbog = 3
                
            "No": 
                lady "A child is lost, but is it him?"
                
        jump night1
        
        
    elif cbog is "3":
        lady "The answers have been found?"
        menu:
            "Yes":
                if $ riddles is 3:
                    lady "Corn, Wine, Sand. Yes, these are all I requested, but the last riddle has yet been unsolved?"
                    menu:
                        "Where can I find it?":
                            lady "No where."
                            ruby "Quit jerkin' us around. We found nothing, lady."
                            lady "..."
                            lady "Yes. Exactly. Nothing."
                            
                        "I couldn't find anything.":
                            lady "There is nothing to be found."
                            ruby "That's what [mc] said, lady. We found nothing!"
                            lady "..."
                            lady "Yes. Exactly. Nothing."
                            
                        "...":
                            lady "Correct."
                            lady "The answer... is nothing."
                    
                    lady "Answers restored once more, no longer lost to the blackness of limbo."
                    lady "You may have the child, but know that with me he shall be free. With them he will be chained."
                    
                    menu:
                        "What do you mean?":
                            lady "He's inflicted with with the domain. Crystalline venom coursing through his veins. He will die, like many others."
                            
                        "Sounds fake, but okay.":
                            lady "Skepticism breeds answers. A fine trait."
                            lady "He's inflicted with with the domain. Crystalline venom coursing through his veins. He will die, like many others."
                            
                        "...":
                            lady "He's inflicted with with the domain. Crystalline venom coursing through his veins. He will die, like many others."
                            
                    lady "I ache to heal their wounds, but appearances are everything."
                    $ cbog = 4
                    
                else:
                    lady "You seem to be missing something. Come back when you've found it all."
                
                
            "No":
                lady "Return when you've found it all."
                
        jump night1
        
        
    elif cbog is "4":
        lady "Need help with something?"
        menu:
            "Yes":
                "I have no perspective to give at the moment."
            "No":
                lady "Walk with kindness, [mc]."
                
    jump night1
    
    else:
        lady "You shouldn't be here... the creator didn't code it that way."
    
    jump night1


I originally had the code as:

if cbog == 1:
elif cbog == 2:
else:

but it gave me an error saying:

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/nzone.rpy", line 104: expected statement.
    elif cbog == 2:
              ^

File "game/nzone.rpy", line 134: expected statement.
    elif cbog == 3:
              ^

File "game/nzone.rpy", line 192: expected statement.
    elif cbog == 4:
              ^

File "game/nzone.rpy", line 202: expected statement.
    else:
        ^

Ren'Py Version: Ren'Py 6.99.13.2919

I feel like I'm missing something dumb, here. My other if/else statements within the if/elif/else statements work fine. I checked the indentation, but to be fair I'm doing this with little sleep so I definitely could have missed something. I genuinely don't understand what mistake I'm making. The code looks fine to me? I've even compared it against the renpy documentation examples, and still can't figure it out. I also tried adding init python: at the beginning of all of it but it gives me another error where my labels are basically useless. Any help is appreciated, and even more appreciated if it's explained in laymen terms.
Last edited by jingleriot on Wed Apr 25, 2018 4:20 pm, edited 1 time in total.

KingsCard
Newbie
Posts: 14
Joined: Sat Feb 17, 2018 8:58 am
Contact:

Re: Issue with if/elif/else statements

#2 Post by KingsCard »

Watch your indentation, you have a label at the same level as a if statement. Also, a conditionnal menu should be written like that and finaly you have to be careful about strings and numbers.

Code: Select all

default num = 0
default state = True
default string = "ok"

label start:
    if state:
        menu:
            "I can only choose 0" if num == 0:
                $ num = 1
            "Now I can choose 1" if num == 1:
                $ num = 0
            "My variable {b}typo{/b} is [string]" if string == "ok":
                $ string = "nok"
            "My variable {b}typo{/b} is [string]" if string == "nok":
                $ string = "ok"
            "I don't want to see this menu anymore":
                $ state = False
    else:
        menu:
            "I want to see the menu finaly":
                $ state = True
    jump start



kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Issue with if/elif/else statements (Expected statement error)

#3 Post by kivik »

The reason for your error is because you've got a label mixed in with your code during your main if block. I'm guessing that's either a mistake or you're trying to create a [a=https://www.renpy.org/doc/html/changelo ... cal-labels]local label[/b]? Can't tell by the code since bogcont isn't referenced anywhere within the code you showed us.

You also have incorrect condition statements:

Code: Select all

if pgen = True:
That should be

Code: Select all

if pgen == True: # or if pgen: - it's a programming shorthand for evaluating whether a variable is True or False
Also I'm guessing the code you sent us has been modified, as you've got

Code: Select all

elif cbog is "2":
instead of the following which is shown in the error messages

Code: Select all

elif cbog == "2":
You don't want to use the is operator here - it checks whether two variables are pointing to the same object, not a comparison operator. So you want to stick to == in your code.

I think sorting your label out will fix your error, but the code will behaviour oddly without fixing the conditions.

User avatar
jingleriot
Regular
Posts: 25
Joined: Mon Sep 05, 2016 7:53 pm
Projects: Ventio Mortis, Sector Chimera, Monster Party
Deviantart: jingleriot
itch: https://jingleriotga
Contact:

Re: Issue with if/elif/else statements (Expected statement error)

#4 Post by jingleriot »

THANK YOU BOTH ohhh my god. It was the label indentation that screwed everything up and it's working now (I'll actually play through and test it to be sure, but its at least starting up now).

Post Reply

Who is online

Users browsing this forum: No registered users