[SOLVED] Multiple If-Statements in a Menu

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
AngJo
Newbie
Posts: 10
Joined: Wed Jun 21, 2017 4:22 pm
Contact:

[SOLVED] Multiple If-Statements in a Menu

#1 Post by AngJo »

I'm currently trying to program a Battle Scene into a small visual novel.
The Menu options are : Battle, Equip, Assist and Run
Battle needs to have various if statements and checks.
It needs to check if a sword is equipped, if courage is higher than 5 and if the monster's health is above 0.

I'm currently trying to add an elif to see if Monster Health is above 0 and the sword is equipped, but I get the following error.
Parsing the script failed.
line 41: expected statement.
elif sword ->== True and mhealth >0:
The -> refers to the little red arrow.

The code I'm running is as follows:

Code: Select all

python:
        sword = False
        mhealth = 40
        rint = 3
        
label BattleChoice:
    
    
    menu:
        "Battle":
            if sword == False and rint <5 and mhealth > 0:
                "Attack Missed"
                $ mhealth = mhealth -0
                "MHealth = [mhealth]"
            jump BattleChoice
            elif sword == True and mhealth > 0: (line 41)
                "Critical Hit"
                $ mhealth = mhealth -5
                "MHealth = [mhealth]"
            jump BattleChoice
If I leave out the elif part, it runs the code just fine.

Turns out my indentation for the jump statement wasn't properly alligned. I'm not quite sure why it suddenly started working, as before it would not recognize the jump statement, but I'm not complaining.

Thank you so much.

PS: Does anyone know what the red arrow in error messages is supposed to mean in general? Would like to know for future reference.
Last edited by AngJo on Wed Jun 21, 2017 5:43 pm, edited 2 times in total.

User avatar
Scribbles
Miko-Class Veteran
Posts: 636
Joined: Wed Sep 21, 2016 4:15 pm
Completed: Pinewood Island, As We Know It
Projects: In Blood
Organization: Jaime Scribbles Games
Deviantart: breakfastdoodles
itch: scribbles
Location: Ohio
Contact:

Re: [HELP] Multiple If-Statements in a Menu

#2 Post by Scribbles »

should jump BattleChoice be indented to fall under the initial if statement?

I'm not 100% sure otherwise, why is the (line 41) stuff there? if you just wrote that in the point it out, maybe do it after the line so we can see the indentation?

otherwise, maybe try:

Code: Select all

elif sword and mhealth > 0
you don't need the == True or == False, you can do elif sword or elif not sword

sorry if that doesn't help, I'm not great at programming > <
Image - Image -Image

AngJo
Newbie
Posts: 10
Joined: Wed Jun 21, 2017 4:22 pm
Contact:

Re: [HELP] Multiple If-Statements in a Menu

#3 Post by AngJo »

Scribbles wrote:should jump BattleChoice be indented to fall under the initial if statement?

I'm not 100% sure otherwise, why is the (line 41) stuff there? if you just wrote that in the point it out, maybe do it after the line so we can see the indentation?

otherwise, maybe try:

Code: Select all

elif sword and mhealth > 0
you don't need the == True or == False, you can do elif sword or elif not sword

sorry if that doesn't help, I'm not great at programming > <
I did indeed add the line 41 to show which line the error was referring to. I've changed it to make it more clear. Thanks for the advice.

I've tried the code, but unfortunately that gives the same error message.

And that's no problem at all! I'm glad you were willing to try and help :)

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: [HELP] Multiple If-Statements in a Menu

#4 Post by Imperf3kt »

I agree with Scribbles. The issue as I see it is indentation.

Code: Select all

python:
        sword = False
        mhealth = 40
        rint = 3
        
label BattleChoice:
    
    
    menu:
        "Battle":
            if not sword and rint <5 and mhealth > 0:
                "Attack Missed"
                $ mhealth = mhealth -0
                "MHealth = [mhealth]"
                jump BattleChoice
            elif sword and mhealth > 0: (line 41)
                "Critical Hit"
                $ mhealth = mhealth -5
                "MHealth = [mhealth]"
                jump BattleChoice
How do you get past here though?
Last edited by Imperf3kt on Wed Jun 21, 2017 5:44 pm, edited 1 time in total.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

AngJo
Newbie
Posts: 10
Joined: Wed Jun 21, 2017 4:22 pm
Contact:

Re: [HELP] Multiple If-Statements in a Menu

#5 Post by AngJo »

Imperf3kt wrote:I agree with Scribbles. The issue as I see it is indentation.

Code: Select all

python:
        sword = False
        mhealth = 40
        rint = 3
        
label BattleChoice:
    
    
    menu:
        "Battle":
            if sword == False and rint <5 and mhealth > 0:
                "Attack Missed"
                $ mhealth = mhealth -0
                "MHealth = [mhealth]"
                jump BattleChoice
            elif sword == True and mhealth > 0: (line 41)
                "Critical Hit"
                $ mhealth = mhealth -5
                "MHealth = [mhealth]"
                jump BattleChoice
How do you get past here though?
It was indeed indentation. Turned out the jump should be aligned within the if block.
I'm not sure what you mean with your question.
If you're referring to how the code keeps looping back to BattleChoice, it's because it's only partial code.

Thanks for the help tho :)

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot], Imperf3kt