init?! Python?! Urgh o.o" [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
manga_otaku
Veteran
Posts: 413
Joined: Fri May 20, 2011 1:27 pm
Completed: [KN] Saving Project: Blind? (Part One)
Contact:

init?! Python?! Urgh o.o" [SOLVED]

#1 Post by manga_otaku »

I'm trying out the user choices by using variables and testing for equality sign thingy. I've done what http://lemmasoft.renai.us/forums/postin ... e=post&f=8 has, but it doesn't work. Instead, it comes up with this:
While running game code:
File "game/script.rpy", line 566, in script
menu:
File "game/script.rpy", line 573, in python
"Ask the person in the next seat." if ask:
NameError: name 'ask' is not defined

-- Full Traceback ------------------------------------------------------------

Full traceback:
File "C:\Users\Anita\Documents\Games\PC\VN\renpy-6.12.1\renpy\execution.py", line 261, in run
File "C:\Users\Anita\Documents\Games\PC\VN\renpy-6.12.1\renpy\ast.py", line 1197, in execute
File "C:\Users\Anita\Documents\Games\PC\VN\renpy-6.12.1\renpy\exports.py", line 414, in menu
File "C:\Users\Anita\Documents\Games\PC\VN\renpy-6.12.1\renpy\python.py", line 997, in py_eval
File "game/script.rpy", line 573, in <module>
NameError: name 'ask' is not defined
And then when I click ignore it skips to the scene I want it to go to anyway?!
What does it mean by not 'defined'?! =.=

By the way, this is what I put and when I use it:
menu:
"Sit down anyway.":
$ sit = True
y "Oh well. I'll sit down anyway."
jump sit

"Ask the person in the next seat.":
$ ask = True
y "I suppose I should ask someone."
jump ask
Then when I wanted to use it...
menu:
"Wait until Sensei arrives":
"I should wait until Sensei arrives."
jump senarrive
"Sit down anyway." if sit:
"I may as well...I mean. Seats haven't been assigned yet have they?"
jump sit1
"Ask the person in the next seat." if ask:
"I decided to ask the person sitting in the next seat."
jump ask1
I have an 'init:' thing at the top of the script (if it's meant to go there >_> Bear with me, first time using Ren'Py for a actual project. Used to use Novelty, still am, but I wanted to try this out :D)
Last edited by manga_otaku on Sun May 29, 2011 6:52 am, edited 3 times in total.
Projects:
WIP|[KN] Day Of Reckoning|
Completed|[KN] Saving Project Blind: Part One|[KN] Saving Project Blind: Part Two|[KN] Saving Project Blind: Final Part|
Is available to help with proof-reading (Grammar freak...) Maybe voice-acting in the near future x]

User avatar
redcat
Regular
Posts: 189
Joined: Thu Oct 30, 2008 9:30 am
Contact:

Re: What have I done wrong? :S

#2 Post by redcat »

@manga_otaku--> have you declared the variable in the init section?
Meowwngg...??

Elenakiara
Veteran
Posts: 285
Joined: Tue Dec 28, 2010 9:40 am
Projects: (WIP) Caesar's Fate
Location: Canada
Contact:

Re: What have I done wrong? :S

#3 Post by Elenakiara »

[quote="manga_otaku"]
I second the suggestion of redcat. Also, I remember that when I tried that code myself, I'd usually put something like:

Code: Select all

"Ask the person in the next seat." if pick == "ask":
        "I turn around to face XYZ."
        jump ask1
Sometimes, it wouldn't like the jump being right after something with a variable. xD I hope that you find the solution still.[/color]
Working on a visual novel : Caesar's Fate (GxB) : Follow me on Twitter or visit my Website for updates!
Image

manga_otaku
Veteran
Posts: 413
Joined: Fri May 20, 2011 1:27 pm
Completed: [KN] Saving Project: Blind? (Part One)
Contact:

Re: What have I done wrong? :S

#4 Post by manga_otaku »

redcat wrote:@manga_otaku--> have you declared the variable in the init section?
I just realised I haven't got an init section O.O...help? :D (Sorry slow newb here >3<")

EDIT: Put an init in =.=
Projects:
WIP|[KN] Day Of Reckoning|
Completed|[KN] Saving Project Blind: Part One|[KN] Saving Project Blind: Part Two|[KN] Saving Project Blind: Final Part|
Is available to help with proof-reading (Grammar freak...) Maybe voice-acting in the near future x]

KimiYoriBaka
Miko-Class Veteran
Posts: 636
Joined: Thu May 14, 2009 8:15 pm
Projects: Castle of Arhannia
Contact:

Re: init?! Python?! Urgh o.o"

#5 Post by KimiYoriBaka »

okay, two things.

1. what's important about defining variables beforehand is not that you declare them in the init section. this is just a convenient place to put them. the important thing is that you give it a starting value at some point before using it so that the program knows what kind of variable it is.

2. the reason your code had a problem is because you used two variables to check which menu options that should be displayed, but set them up so that only one would actually have a value.

when it says "undefined" it means exactly that. that you didn't define the variable before using it. if you want to use two variable for those choices you should set them both to false sometime before the choice that set one of the to true

manga_otaku
Veteran
Posts: 413
Joined: Fri May 20, 2011 1:27 pm
Completed: [KN] Saving Project: Blind? (Part One)
Contact:

Re: init?! Python?! Urgh o.o"

#6 Post by manga_otaku »

Alright. I don't get where I'm meant to define and how =.= I apologise in advance if I light any irritancy to anyone.
Projects:
WIP|[KN] Day Of Reckoning|
Completed|[KN] Saving Project Blind: Part One|[KN] Saving Project Blind: Part Two|[KN] Saving Project Blind: Final Part|
Is available to help with proof-reading (Grammar freak...) Maybe voice-acting in the near future x]

HigurashiKira
Miko-Class Veteran
Posts: 832
Joined: Mon Nov 01, 2010 9:10 pm
Contact:

Re: init?! Python?! Urgh o.o"

#7 Post by HigurashiKira »

Ok then, here's an example:

Code: Select all

label start:
    
    $ flagrewind = False
    $ flagspeedup = False
#Game stuff here

   "Should I rewind it or speed it up?"

menu:
        
        "Rewind it":
            $ flagrewind = True
 
        "Speed it up":
            $ flagspeedup = True
label tape:

    if flagrewind == True 
       jump rewindmovie
    if flagspeedup == True 
       jump speedmovie
I have moved to a new account. Please contact me here from now on. T/Y~

User avatar
redcat
Regular
Posts: 189
Joined: Thu Oct 30, 2008 9:30 am
Contact:

Re: init?! Python?! Urgh o.o"

#8 Post by redcat »

@manga_otaku--> Have you tried the Renpy's demo game and analyze it's script? If you haven't, then try it now.
There are also many of open source games in LSF. Try download some of them. You can learn something by looking into their script.rpy and then copy & modify the code to meet your requirements.

If you still having difficulties, perhaps you might want to show your script.rpy as attachment in your post (with the risk of spoiling your story). Usually, some programmers would be kind enough to help you point out what's wrong with your script.
Meowwngg...??

manga_otaku
Veteran
Posts: 413
Joined: Fri May 20, 2011 1:27 pm
Completed: [KN] Saving Project: Blind? (Part One)
Contact:

Re: init?! Python?! Urgh o.o"

#9 Post by manga_otaku »

Ahah! Thank you xD It works now :)
Projects:
WIP|[KN] Day Of Reckoning|
Completed|[KN] Saving Project Blind: Part One|[KN] Saving Project Blind: Part Two|[KN] Saving Project Blind: Final Part|
Is available to help with proof-reading (Grammar freak...) Maybe voice-acting in the near future x]

Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot]