If statement problem

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
Mooneon
Regular
Posts: 78
Joined: Sat Jul 04, 2015 4:05 pm
Contact:

If statement problem

#1 Post by Mooneon »

So I am now coding in if statements and I am new to it, COMPLETELY. So I need help with this.

In my story. The protagonist is called Umaris. And in the part of the story. There's an menu option. There's one to meet Reptile and One to Meet Ermac. So, if the player chose to meet Reptile FIRST, BEFORE ERMAC,than this would happen.:

Code: Select all

# If Umaris met Reptile before Ermac, this would happen. 
if Oh_Reptile == True:
    u normal talk "Oh yes.. I've met him just a while ago."
    u "He is very threatening.."
    u "But.. I suppose I understand now.."
    e "He is very impudent. Yet that is what he is."

But if Umaris didn't this would happen.

Code: Select all

if Oh_Reptile == False:    
    hide ermac normal talk
    show ermac normal
    u normal talk "I.. Probaly haven't met him."    
Okay so the problem is that. I want it to work if the player met Reptile FIRST and then they would get the if True statement.
But if the player didn't, then they would get the False statement.
SO. How do I do this?

User avatar
namastaii
Eileen-Class Veteran
Posts: 1350
Joined: Mon Feb 02, 2015 8:35 pm
Projects: Template Maker for Ren'Py, What Life
Github: lunalucid
Skype: Discord: lunalucid#1991
Soundcloud: LunaLucidMusic
itch: lunalucid
Location: USA
Contact:

Re: If statement problem

#2 Post by namastaii »

Is this all happening just with a menu choice? Then simply...

Code: Select all

menu: 
    "Meet Reptile":
        jump meet_reptile
    "Meet Ermac":
        jump meet_ermac
        
label meet_reptile:
    u normal talk "Oh yes.. I've met him just a while ago."
    u "He is very threatening.."
    u "But.. I suppose I understand now.."
    e "He is very impudent. Yet that is what he is."
    jump somewhere_else
    
label meet_ermac:
    hide ermac normal talk
    show ermac normal
    u normal talk "I.. Probaly haven't met him." 
    jump somewhere_else  
For something like your example, you wouldn't even need an if statement. This would be the easiest way, I believe.

User avatar
Mooneon
Regular
Posts: 78
Joined: Sat Jul 04, 2015 4:05 pm
Contact:

Re: If statement problem

#3 Post by Mooneon »

ahhhhh.... Um. Not exactly what I had in mind
Okay here's the full script. I just didn't want to put too much.

Okay here's the menu choices

Code: Select all

    menu:
     "...Where should I go?"
     "Go to the green glowing underground.":
         jump underground
     "Head to the Outworld Garden.":
         jump garden
and Here's the whole conversation with both characters

Code: Select all

#THIS PART IS WHERE SHE MEETS ERMAC
label underground:

    play music "_A_glimpse_into_the_lair.mp3"
    scene black with Dissolve(1.0)
    scene lair with Dissolve(1.0)
    "...W-what is this?"
    who "You should not be here."
    show ermac normal with dissolve
    
    u sad talk "A-apologizes! I did not mean to come here unnoticed!"
    u "I was only curious."
    u normal talk "...My name is Umaris. I am new here.."
    hide ermac normal
    show ermac normal talk 
    who "We know. We saw your presence with the Kahn."
    hide ermac normal talk
    show ermac normal
    u "...And what is.. Your name..?"
    
    hide ermac normal
    show ermac normal talk
    who "We are called Ermac."
    e "We have not seen your kind ever before."
    hide ermac normal talk
    show ermac normal
    

    u sad talk "Well, neither have I, in a long time.."
    hide ermac normal
    show ermac normal talk
    e "Your race is gone as well?"
    hide ermac normal talk
    show ermac normal
    u confused talk "What do you mean by that?"
    hide ermac normal 
    show ermac normal talk
    e "There is another ally with us. He is called reptile."
    e "His race has been extinct for many years.."
    
# If Umaris met Reptile before Ermac, this would happen. 
if Oh_Reptile == True:
    u normal talk "Oh yes.. I've met him just a while ago."
    u "He is very threatening.."
    u "But.. I suppose I understand now.."
    e "He is very impudent. Yet that is what he is."

#IF Umaris did not meet Reptile before, than this would happen.    
    hide ermac normal talk
    show ermac normal
    u normal talk "I.. Probaly haven't met him."
    
#And then the that part ends and the story continues.

    u confused talk "..Why do you call yourself, we?"
    hide ermac normal
    show ermac normal talk
 
    
    e "We are a collective of souls."
    u sad talk "A b-body with how m-many souls?"
    e "Ten thousand."
    e "You seem afraid. We understand.."
    hide ermac normal talk
    show ermac normal
    u normal talk "I am not. I am just .. Shocked."
    u "There seems to be many different people here.."
    u "With lots of.. different things about them."
    
    jump nextscene2

#MEETING REPTILE
label garden:
    
    play music "David_Szesztay_-_Backyard.mp3"
    scene black with Dissolve(1.0)
    scene garden with dissolve
    "Mmm. Lovely scenery.."
    "The flowers of this world was beautiful yet different in a good way."
    "In a slight feel. I could feel and hear breathing."
    "I turn my back to see if anyone was here."
    
    show reptile normal talk with dissolve
    who "You are the enforcer who has joined our court."
    hide reptile normal talk
    show reptile normal
    "It hisses at the end of the sentence."
    "I feel as scared as an elk looking among a wolf."
    u sad talk "W-who are you?"
    hide reptile normal
    show reptile normal talk
    
    who "I am called Reptile."
    hide reptile normal talk
    show reptile normal
    "It slowly circles me.."
    u normal talk "What do you want..?"
    hide reptile normal
    show reptile normal talk
    r "I want to taste your fresh and different blood."
    r "Ssince you are very different to my eyes."
    
    hide reptile normal talk
    show reptile normal
    u sad talk "D-do you eat people..??"
    "I don't need to stick here much longer."
    "But no. If I show him that I'm afraid. It will be a bad start for me. And might actually get a bit of me."
    u normal talk "Apologizes. I don't think I will be staying here much longer."
    r "I do not trust you, yet. I hope to get the chance to taste your blood."
    
    hide reptile talk with moveoutleft
    
    u sad talk "I do not know what I gotten myself into.."
    scene black with Dissolve(1.0)
    
#If the player picked to meet with Reptile first than we get to meet Ermac and then the next scene.
     jump underground
#But if the player didnt pick to meet reptile first than it goes to the next scene
I hope you get it. The point is that this PART SHOULD show(The code down below), so that the player meets with REPTILE FIRST. Because if the player meets with reptile first then UMARIS will mention him with the conversation with Ermac. IF NOT then she will say that she hasn't met with him yet.

Code: Select all

# If Umaris met Reptile before Ermac, this would happen. 
if Oh_Reptile == True:
    u normal talk "Oh yes.. I've met him just a while ago."
    u "He is very threatening.."
    u "But.. I suppose I understand now.."
    e "He is very impudent. Yet that is what he is."

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: If statement problem

#4 Post by trooper6 »

What about something like:

Code: Select all

default met_first = "None"

label start:
    "blah blah blah"

    menu:
     "...Where should I go?"
     "Go to the green glowing underground.":
        if met_first == "None":
            met_first = "ermac"
         jump underground
     "Head to the Outworld Garden.":
        if met_first == "None"
            met_first = "reptile"
         jump garden

Then later in your underground code:

Code: Select all

    e "There is another ally with us. He is called reptile."
    e "His race has been extinct for many years.."
    if met_first == "reptile":
        u normal talk "Oh yes.. I've met him just a while ago."
        u "He is very threatening.."
        u "But.. I suppose I understand now.."
        e "He is very impudent. Yet that is what he is."
    else: 
        hide ermac normal talk
        show ermac normal
        u normal talk "I.. Probaly haven't met him."
    u confused talk "..Why do you call yourself, we?"
    hide ermac normal
    show ermac normal talk
and in your garden label:

Code: Select all

    u sad talk "I do not know what I gotten myself into.."
    scene black with Dissolve(1.0)
    
    if met_first == "reptile":
        jump underground
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Mooneon
Regular
Posts: 78
Joined: Sat Jul 04, 2015 4:05 pm
Contact:

Re: If statement problem

#5 Post by Mooneon »

Sorry this is random but there's something a bit with the indention here. Can you help just for a quickie?
I tried fixing it on my own. But somehow can't get it working.
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/script.rpy", line 333: indentation mismatch.

Ren'Py Version: Ren'Py 6.99.10.1227
the line indention is "jump underground"

Code: Select all

    menu:
     "...Where should I go?"
     "Go to the green glowing underground.":
        if met_first == "None":
            met_first = "ermac"
         jump underground
     "Head to the Outworld Garden.":
        if met_first == "None"
            met_first = "reptile"
         jump garden

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: If statement problem

#6 Post by trooper6 »

Mooneon wrote:Sorry this is random but there's something a bit with the indention here. Can you help just for a quickie?
I tried fixing it on my own. But somehow can't get it working.

Code: Select all

    menu:
     "...Where should I go?"
     "Go to the green glowing underground.":
        if met_first == "None":
            met_first = "ermac"
         jump underground
     "Head to the Outworld Garden.":
        if met_first == "None"
            met_first = "reptile"
         jump garden
Every time you have a colon, you should indent 4 spaces. If you are using Editra, you can use a tab. Once you are finished with that block that the colon started, you outdent 4 spaces.

So it should be:

Code: Select all

label start: #no indentation, but everything after this colon that is part of label start should be indented 4 spaces
    menu: #4 spaces, the things that are part of the menu should be indented 8 spaces
        "...Where should I go?" #8 spaces
        "Go to the green glowing underground.": #8 spaces, the things part of 'go to the green glowing underground' should be 12 spaces
            if met_first == "None": #12 spaces, things that are part of 'if met_first..." should be 16 spaces
                met_first = "emac" #16 spaces, we are now finished with the 'if met_first block so the next line should be outdented
            jump underground #12 spaces, because this is still part of 'go to the green glowing underground'
        "Head to the Outworld Garden.": #8 spaces, because this is part of the menu, things part of 'head to the outworld..." should be 12 spaces
            if met_first == "None" #12 spaces, things that are part of 'if met_first..." should be 16 spaces
                met_first = "reptile" #16 spaces, we are now finished with the 'if met_first block so the next line should be outdented
            jump garden #12 spaces, because this is still part of 'go to the green glowing underground'
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Mooneon
Regular
Posts: 78
Joined: Sat Jul 04, 2015 4:05 pm
Contact:

Re: If statement problem

#7 Post by Mooneon »

Holy crap im spending a long time fixing this.
PLEASE PLEASE HELP. The label start is before the menu by the way.. This is what is before the menu choice.

Code: Select all

    #CHAPTER 2 - DIBATRIBE
    play music "Alan_Singley_-_Unknown_Variables.mp3"
    scene hallway 1 with Dissolve(1.0)
    "On the path of the Emperor's castle. Erron showed me everywhere."
    "Rooms and important rooms. But I know it's not all of it.."
    show erron normal with dissolve
    eb "Just to let you know. The emperor still can't trust you. Don't do something you might regret."
    eb "You have to follow by rules."
    eb "I will be watching you."
    hide erron normal with fade
    "*Sighs*"
    "I am not sure about this world.. Or this place."
    "I would like to explore a bit of this place a bit more.."

menu:
    "...Where should I go?"
    "Go to the green glowing underground.":
        if met_first == "None":
              met_first = "ermac"
        jump underground
    "Head to the Outworld Garden.":
         if met_first == "None":
               met_first = "reptile"
         jump garden
I did do the number spaces on each line it's just when I reload the game it gives me an error. So I decided to fix the lines myself.

lol this is the error. (Sorry I am actually crying in frustration. And I am really sorry if I am super annoying."

Code: Select all

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


File "game/script.rpy", line 332: expected statement.
    met_first = "ermac"
              ^

File "game/script.rpy", line 336: expected statement.
    met_first = "reptile"
              ^

Ren'Py Version: Ren'Py 6.99.10.1227

User avatar
78909087
Veteran
Posts: 277
Joined: Sat Aug 16, 2014 2:33 pm
Completed: Dungeons and Don't Do It, Wake Up
Projects: Lethe
IRC Nick: Pacermist
Contact:

Re: If statement problem

#8 Post by 78909087 »

Code: Select all

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


File "game/script.rpy", line 332: expected statement.
    met_first = "ermac"
              ^

File "game/script.rpy", line 336: expected statement.
    met_first = "reptile"
              ^

Ren'Py Version: Ren'Py 6.99.10.1227
[/quote]

It looks like you are just missing the python statement...
The code that is shown to be wrong should be this:

Code: Select all

menu:
    "...Where should I go?"
    "Go to the green glowing underground.":
        if met_first == "None":
              $ met_first = "ermac"
        jump underground
    "Head to the Outworld Garden.":
         if met_first == "None":
               $ met_first = "reptile"
         jump garden
Lint is picking up that there are no '$' before the statements, so it can't make them python... I think.

Apologies in advance if I'm wrong, I only skimmed the above.
I am not friends with the sun.
Image

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: If statement problem

#9 Post by trooper6 »

Mooneon wrote:Holy crap im spending a long time fixing this.
PLEASE PLEASE HELP. The label start is before the menu by the way.. This is what is before the menu choice.

Code: Select all

    #CHAPTER 2 - DIBATRIBE
    play music "Alan_Singley_-_Unknown_Variables.mp3"
    scene hallway 1 with Dissolve(1.0)
    "On the path of the Emperor's castle. Erron showed me everywhere."
    "Rooms and important rooms. But I know it's not all of it.."
    show erron normal with dissolve
    eb "Just to let you know. The emperor still can't trust you. Don't do something you might regret."
    eb "You have to follow by rules."
    eb "I will be watching you."
    hide erron normal with fade
    "*Sighs*"
    "I am not sure about this world.. Or this place."
    "I would like to explore a bit of this place a bit more.."

menu:
    "...Where should I go?"
    "Go to the green glowing underground.":
        if met_first == "None":
              met_first = "ermac"
        jump underground
    "Head to the Outworld Garden.":
         if met_first == "None":
               met_first = "reptile"
         jump garden
I did do the number spaces on each line it's just when I reload the game it gives me an error. So I decided to fix the lines myself.

lol this is the error. (Sorry I am actually crying in frustration. And I am really sorry if I am super annoying."

Code: Select all

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


File "game/script.rpy", line 332: expected statement.
    met_first = "ermac"
              ^

File "game/script.rpy", line 336: expected statement.
    met_first = "reptile"
              ^

Ren'Py Version: Ren'Py 6.99.10.1227
Pardon me, it is 4:30am where I'm at so I'm a bit tired. Whenever you assign a variable, that is a Python thing, so you need to precede the line with a $.

Also, you shouldn't be outdenting that menu, since that menu is part of the block that is the chapter two label.

So:

Code: Select all

    #CHAPTER 2 - DIBATRIBE
    play music "Alan_Singley_-_Unknown_Variables.mp3"
    scene hallway 1 with Dissolve(1.0)
    "On the path of the Emperor's castle. Erron showed me everywhere."
    "Rooms and important rooms. But I know it's not all of it.."
    show erron normal with dissolve
    eb "Just to let you know. The emperor still can't trust you. Don't do something you might regret."
    eb "You have to follow by rules."
    eb "I will be watching you."
    hide erron normal with fade
    "*Sighs*"
    "I am not sure about this world.. Or this place."
    "I would like to explore a bit of this place a bit more.."

    menu:
        "...Where should I go?"
        "Go to the green glowing underground.":
            if met_first == "None":
                $ met_first = "ermac"
            jump underground
        "Head to the Outworld Garden.":
            if met_first == "None":
                $ met_first = "reptile"
            jump garden
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Mooneon
Regular
Posts: 78
Joined: Sat Jul 04, 2015 4:05 pm
Contact:

Re: If statement problem

#10 Post by Mooneon »

Thank you all. You cured cancer.

Sorry just kidding. I am really F%#&ING glad. Like seriously thank you for the help! God bless you all. I apologize for the fricking stupid, annoying and idiotic responds from me. THANK YOU

Post Reply

Who is online

Users browsing this forum: Google [Bot], MSN [Bot]