name 'part' is not defined

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
Gear
Miko-Class Veteran
Posts: 764
Joined: Tue Apr 05, 2011 10:15 pm
Projects: Tempestus Sum
Organization: Xenokos Interactive
IRC Nick: Gear
Skype: Skye.Gear
Location: Grand Prairie, TX
Contact:

name 'part' is not defined

#1 Post by Gear » Mon Jan 28, 2013 4:41 pm

This is a very vague problem, since I don't know where it's happening. I'm going to do my best to explain, and if you need more information, I can provide it.

My game runs perfectly fine under normal circumstances. However, if I'm in the game, then go to the menu and click "Main Menu," I get this. If I hit "Ignore," it rounds back to my 'start' label instead of back to the main menu. If I stay at that point (my start label leads directly to a menu) and open the menu, and click on main menu again, it asks for confirmation like normal, then takes me back to the main menu if I select yes. It's not giving me much info to work with, as I can't identify where the problem is. My best guess is a bit of code actually called 'part' at the very beginning of my script file.

Code: Select all

init -1 python:
    def threepart(prefix,suffix):
        return ConditionSwitch(
            "part == 1", prefix + "/1/" + suffix + ".png",
            "part == 2", prefix + "/2/" + suffix + ".png",
            "part == 3", prefix + "/3/" + suffix + ".png")
This piece of code was designed to identify which part of the game you're in, and alters the sprite file name to use as a result. It's also tied to this code here:

Code: Select all

label start:
    $ part = 1
...which, as you can see, is immediately after the start label as well. Why it's not detecting this, I do not know, if that even IS the problem. Because the game hasn't been fully written yet, there is not yet any place where parts 2 or 3 are activated.

So, does anyone have any insight?
The best reason to get up in the morning is to outdo yourself: to do it better than you've ever done it before. But if you haven't done it better by nightfall... look at your globe and pick a spot: it's always morning somewhere.

User avatar
Alex
Lemma-Class Veteran
Posts: 2981
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: name 'part' is not defined

#2 Post by Alex » Mon Jan 28, 2013 5:13 pm

Why don't you add one more condition that is "True"?
http://www.renpy.org/doc/html/displayab ... splayables

User avatar
Ayutac
Regular
Posts: 150
Joined: Thu Oct 18, 2012 2:23 pm
Projects: Pokémon Dating Sim
Organization: A Breeze Of Science
Deviantart: Ubro
Location: Mayence, Germany
Contact:

Re: name 'part' is not defined

#3 Post by Ayutac » Mon Jan 28, 2013 11:44 pm

initialization happens before start. I got this problem, too, and then put the definition of the variables (in your example currently after start) into "early" (see options.rpy at the end), which is before any init. Recently someone brought up that saving issues could happen this way, but I can't find it right now and it all works for me... (In my example, the flag for a secret location is initialized there, just tested it, works fine after save/close game/launch game/load)
Up next: An original, open source, text-based Dating Sim. Stay tuned ;)

User avatar
Gear
Miko-Class Veteran
Posts: 764
Joined: Tue Apr 05, 2011 10:15 pm
Projects: Tempestus Sum
Organization: Xenokos Interactive
IRC Nick: Gear
Skype: Skye.Gear
Location: Grand Prairie, TX
Contact:

Re: name 'part' is not defined

#4 Post by Gear » Wed Jan 30, 2013 12:59 am

@Alex: I'm not sure what you mean. I sadly don't fully understand the code I'm using, since PyTom's the one who wrote it. My understanding is...cursory, at best.

@Ayutac: I will have to try that and post my results here. Thanks.
The best reason to get up in the morning is to outdo yourself: to do it better than you've ever done it before. But if you haven't done it better by nightfall... look at your globe and pick a spot: it's always morning somewhere.

User avatar
Alex
Lemma-Class Veteran
Posts: 2981
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: name 'part' is not defined

#5 Post by Alex » Wed Jan 30, 2013 1:56 pm

Ah, sorry, I meant

Code: Select all

init -1 python:
    def threepart(prefix,suffix):
        return ConditionSwitch(
            "part == 1", prefix + "/1/" + suffix + ".png",
            "part == 2", prefix + "/2/" + suffix + ".png",
            "part == 3", prefix + "/3/" + suffix + ".png",
            "True", prefix + "/1/" + suffix + ".png"
            )

User avatar
Gear
Miko-Class Veteran
Posts: 764
Joined: Tue Apr 05, 2011 10:15 pm
Projects: Tempestus Sum
Organization: Xenokos Interactive
IRC Nick: Gear
Skype: Skye.Gear
Location: Grand Prairie, TX
Contact:

Re: name 'part' is not defined

#6 Post by Gear » Fri Feb 01, 2013 2:39 pm

Excuse me if I'm wrong about this, but would that mean that if part == true, then part == 1 as well? What if it became false, would the error return, or...?
The best reason to get up in the morning is to outdo yourself: to do it better than you've ever done it before. But if you haven't done it better by nightfall... look at your globe and pick a spot: it's always morning somewhere.

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: name 'part' is not defined

#7 Post by nyaatrap » Fri Feb 01, 2013 7:35 pm

"part == 1", prefix + "/1/" + suffix + ".png" means if "part == 1" is TRUE, then prefix + "/1/" + suffix + ".png" is used.
so just "True" (or other non-zero value) means if "True" is TRUE, then prefix + "/1/" + suffix + ".png" is used.
False (or zero) do nothing. It's just pass to the next assessment. So putting "True" at the last assessment prevents all assessments become False.

User avatar
Gear
Miko-Class Veteran
Posts: 764
Joined: Tue Apr 05, 2011 10:15 pm
Projects: Tempestus Sum
Organization: Xenokos Interactive
IRC Nick: Gear
Skype: Skye.Gear
Location: Grand Prairie, TX
Contact:

Re: name 'part' is not defined

#8 Post by Gear » Wed Feb 06, 2013 6:06 pm

It makes sense, but adding that bit of code in got me this when I tried to start the game up.
The best reason to get up in the morning is to outdo yourself: to do it better than you've ever done it before. But if you haven't done it better by nightfall... look at your globe and pick a spot: it's always morning somewhere.

Post Reply

Who is online

Users browsing this forum: Google [Bot], _ticlock_