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
kuzai
Regular
Posts: 85
Joined: Sat May 12, 2012 8:15 pm
Projects: Custom Lover, PuppyShipping DWH, Yu-Gi-Oh!: Chat
Location: Canada
Contact:

If Statement Problem

#1 Post by kuzai » Sat May 18, 2013 6:49 pm

Hey everyone I am having trouble with a certain 'if statement' and I already tried looking around the place for answers but nothing so far has helped.

I don't know what I am doing wrong with it but every time I try to get past this certain point in my game to test it an error keeps popping up saying

Code: Select all

NameError: name 'beg_pillow' is not defined
and I haven't the slightest clue what it's talking about because here is my script for it so far

Code: Select all

label Beg:
    
    $  beg_pillow = True
    
    j "If he wants me to go out looking for his things he's going to have to work for it as well"
    jump done2
And then later on in the game

Code: Select all

mw "Gimme! Gimme! Gimme! Gimme! Gimme!"
    
    if beg_pillow:
        j "You want it that much?"
        mw "yeaaaaah! I want my pillow! I want my pillow!"
So if anyone knows why it's not working please tell me. And thank you in advance
I forgive and forget. Because I have a good heart and terrible memory

User avatar
xavimat
Eileen-Class Veteran
Posts: 1433
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love, unknown
Organization: Pilgrim Creations
Github: xavi-mat
itch: xavimat
Location: Italy
Contact:

Re: If Statement Problem

#2 Post by xavimat » Sat May 18, 2013 7:08 pm

It seems that not going to "label Beg" leaves the variable undefined (is there somewhere a "$ beg_pillow = False" line?)
I thinks it's better to initialize all variables at the beginning of the "label start:" to avoid these problems.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Cops&Robbers A two-player experiment
Fear&Love Why can’t we simply express our feelings? Why am I afraid to say ‘I love you’?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

User avatar
kuzai
Regular
Posts: 85
Joined: Sat May 12, 2012 8:15 pm
Projects: Custom Lover, PuppyShipping DWH, Yu-Gi-Oh!: Chat
Location: Canada
Contact:

Re: If Statement Problem

#3 Post by kuzai » Sat May 18, 2013 7:17 pm

xavimat wrote:It seems that not going to "label Beg" leaves the variable undefined (is there somewhere a "$ beg_pillow = False" line?)
I thinks it's better to initialize all variables at the beginning of the "label start:" to avoid these problems.

There isn't a $ beg_pillow = False but I have tried putting one in and I still got the same error.

What do you mean by 'initialize all variables at the beginning of the label start:'?
I forgive and forget. Because I have a good heart and terrible memory

User avatar
Googaboga
Eileen-Class Veteran
Posts: 1382
Joined: Wed Dec 12, 2012 1:37 pm
Completed: https://gbpatch.itch.io/
Projects: Floret Bond, XOXO Blood Droplets, Our Life
Organization: GB Patch Games
Tumblr: gb-patch
itch: gbpatch
Contact:

Re: If Statement Problem

#4 Post by Googaboga » Sat May 18, 2013 7:40 pm

When you add a variable the code needs to go through the part where you the defined variable if you want it to be defined later in the game.

When you make a new game there is automatically a label start. Beneath that label you code things to make your first scene, add in dialog, etc. But most people define variables before they actually start making scenes or conversations. So go to the very start of your game and you'll see the "start" label. Directly underneath that before any of the other stuff you add to being your game define all the variables you'll have.

Code: Select all

label start:
     $ beg_pillow = False

#The first scene starts now.
      show bg room
      with emily
      play music whatever
      
      emily "Here we are at the start of the game."
Go on with the game and at the right time change it to true and then continue to the if statement.

Oh and when starting the test be sure to load the game from the beginning. If you jump to the middle by loading a saved file or something like that the game won't have noticed the new variable you defined.
In-Progress:
Floret Bond, XOXO Blood Droplets, Our Life
Released:
A Foretold Affair, My Magical Divorce Bureau, XOXO Droplets, Lake of Voices

User avatar
kuzai
Regular
Posts: 85
Joined: Sat May 12, 2012 8:15 pm
Projects: Custom Lover, PuppyShipping DWH, Yu-Gi-Oh!: Chat
Location: Canada
Contact:

Re: If Statement Problem

#5 Post by kuzai » Sat May 18, 2013 9:09 pm

Googaboga wrote:When you add a variable the code needs to go through the part where you the defined variable if you want it to be defined later in the game.

When you make a new game there is automatically a label start. Beneath that label you code things to make your first scene, add in dialog, etc. But most people define variables before they actually start making scenes or conversations. So go to the very start of your game and you'll see the "start" label. Directly underneath that before any of the other stuff you add to being your game define all the variables you'll have.

Code: Select all

label start:
     $ beg_pillow = False

#The first scene starts now.
      show bg room
      with emily
      play music whatever
      
      emily "Here we are at the start of the game."
Go on with the game and at the right time change it to true and then continue to the if statement.

Oh and when starting the test be sure to load the game from the beginning. If you jump to the middle by loading a saved file or something like that the game won't have noticed the new variable you defined.
oh hey thank you very much that helped =D
I forgive and forget. Because I have a good heart and terrible memory

User avatar
Googaboga
Eileen-Class Veteran
Posts: 1382
Joined: Wed Dec 12, 2012 1:37 pm
Completed: https://gbpatch.itch.io/
Projects: Floret Bond, XOXO Blood Droplets, Our Life
Organization: GB Patch Games
Tumblr: gb-patch
itch: gbpatch
Contact:

Re: If Statement Problem

#6 Post by Googaboga » Sat May 18, 2013 9:23 pm

I'm glad. Does your code work now :]?
In-Progress:
Floret Bond, XOXO Blood Droplets, Our Life
Released:
A Foretold Affair, My Magical Divorce Bureau, XOXO Droplets, Lake of Voices

Post Reply

Who is online

Users browsing this forum: No registered users