Error while running code

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
TsukiWorks
Newbie
Posts: 5
Joined: Sat Jun 23, 2018 6:50 am
Projects: The Misunderstood
Deviantart: TsukiWorks
Contact:

Error while running code

#1 Post by TsukiWorks » Tue Jul 10, 2018 9:38 am

Hello. I was testing out some things in Ren'Py, but I am still new to programming and stuff.
I wanted to add some menu choices which had either a "true" or "false" value.
The player is supposed to make the poem rhyme.
Depending on the choices the player makes, my character is supposed to say different lines.
If all words have a true value, my character will praise the player. If some words have a false value, my character will say something like "It's nice...but I like your previous poems better."
I used if statements for all words with true value, and else for all words with false value.
This error only appears when I choose the wrong words.
I just started learning Python, so please forgive me if I messed it up.
Attachments
Error.png
Script.png

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

Re: Error while running code

#2 Post by Imperf3kt » Tue Jul 10, 2018 9:58 am

The traceback says "light" isn't defined. Do you have a line defining it somewhere near the start of the script?
something like:

Code: Select all

define light = False
or whatever it should be. Check you haven't accidentally capitalised it perhaps, Ren'Py is case-sensitive.
Image

Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

User avatar
TsukiWorks
Newbie
Posts: 5
Joined: Sat Jun 23, 2018 6:50 am
Projects: The Misunderstood
Deviantart: TsukiWorks
Contact:

Re: Error while running code

#3 Post by TsukiWorks » Tue Jul 10, 2018 10:22 am

Imperf3kt wrote:
Tue Jul 10, 2018 9:58 am
The traceback says "light" isn't defined. Do you have a line defining it somewhere near the start of the script?
something like:

Code: Select all

define light = False
or whatever it should be. Check you haven't accidentally capitalised it perhaps, Ren'Py is case-sensitive.
I only wrote their values in the menu choices, but I didn't define them.
So I should define all the words, right?

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

Re: Error while running code

#4 Post by Imperf3kt » Tue Jul 10, 2018 3:15 pm

Yes, you'll need to give them an initial value.
If you're using numbers, just set it to 0 at the start of your game.

This has to be done because without it, Ren'Py doesn't know what you are asking it to check / change.
Image

Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

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

Re: Error while running code

#5 Post by trooper6 » Tue Jul 10, 2018 3:42 pm

Note: if these are values you plan on changing (which is most likely the case), you should use the keyword default rather than define.

You should declare these variables outside of a block.
Like so:

Code: Select all

default light = 0

label start():
    “Game starts here.”
A Close Shave:
*Last Thing Done (Jul 10): Converted LiveComposite Sprites to LayeredImages
*Currently Doing: Trying to work out the transition thing for two character using the same sprite and try to figure out how to redo my multi-barber thing...i.e. see if there is a way to re_do my character callbacks
*First Next thing to do: Rebuild the project with the new RenPy (i.e. with gui.rpy present.), this will mean making some gui art now that I don't have access to the old theme.
*Next thing to do: Code in all the sprite emotion and camera movement for Close Shave Sprite Sections
*Other Thing to Do: Code in all CG and special animation stuff
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
TsukiWorks
Newbie
Posts: 5
Joined: Sat Jun 23, 2018 6:50 am
Projects: The Misunderstood
Deviantart: TsukiWorks
Contact:

Re: Error while running code

#6 Post by TsukiWorks » Thu Jul 12, 2018 2:16 am

trooper6 wrote:
Tue Jul 10, 2018 3:42 pm
Note: if these are values you plan on changing (which is most likely the case), you should use the keyword default rather than define.

You should declare these variables outside of a block.
Like so:

Code: Select all

default light = 0

label start():
    “Game starts here.”
Thanks for answering! Should I change the values from the menu choices, too?

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

Re: Error while running code

#7 Post by trooper6 » Thu Jul 12, 2018 2:20 am

Could you post more of your code? Because I imagine there is a much better way to do whatever you are attempting to do than what it seems like your code snippet is doing.

When you post your code, place it between [ code][ /code] tags (without the extra spaces).
A Close Shave:
*Last Thing Done (Jul 10): Converted LiveComposite Sprites to LayeredImages
*Currently Doing: Trying to work out the transition thing for two character using the same sprite and try to figure out how to redo my multi-barber thing...i.e. see if there is a way to re_do my character callbacks
*First Next thing to do: Rebuild the project with the new RenPy (i.e. with gui.rpy present.), this will mean making some gui art now that I don't have access to the old theme.
*Next thing to do: Code in all the sprite emotion and camera movement for Close Shave Sprite Sections
*Other Thing to Do: Code in all CG and special animation stuff
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
TsukiWorks
Newbie
Posts: 5
Joined: Sat Jun 23, 2018 6:50 am
Projects: The Misunderstood
Deviantart: TsukiWorks
Contact:

Re: Error while running code

#8 Post by TsukiWorks » Thu Jul 12, 2018 11:35 am

trooper6 wrote:
Thu Jul 12, 2018 2:20 am
Could you post more of your code? Because I imagine there is a much better way to do whatever you are attempting to do than what it seems like your code snippet is doing.

When you post your code, place it between [ code][ /code] tags (without the extra spaces).
Sure. I put the words "light" and "tree" as an example:

Code: Select all

default light = 1

default tree = 0 

Code: Select all

menu:
            
            "light":
                $ light = 1
                
            "tree":
                $ tree = 0 

Code: Select all

if light:
        
            k "As expected from you...It's amazing! Wonder what could've given you so much inspiration...or who~."
            
            else:    

            k "Um...it's a nice poem, but your previous ones were better. Sorry..." 

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

Re: Error while running code

#9 Post by trooper6 » Thu Jul 12, 2018 12:40 pm

But it looks like you have lots and lots of these words...all of which lead to one of two responses. So I think there is a much better way of doing what you are aiming for.
So default is the value you give before the game starts.
Then you adjust the values as appropriate in the game.

You could do something just like this:

Code: Select all

default rhymes = True #Let's say that the poem defaults to rhyming.

## The game starts here.
label start:
    "Let's do our first poem--it's a limerick!"
    "The limerck packs laughs anatomical."
    menu:
        "Into space that is quite..."
        "economical":
            pass
        "small":
            $rhymes = False
    "But the good ones I've seen."
    menu:
        "So seldom are..."
        "finished":
            $rhymes = False
        "clean":
            pass
    menu:
        "And the clean ones so seldom are..."
        "comical":
            pass
        "funny":
            $rhymes = False

    if rhymes:
        "As expected from you...It's amazing! Wonder what could've given you so much inspiration...or who~."
    else:
        "Um...it's a nice poem, but your previous ones were better. Sorry..."
    $rhymes = True #Now the poem is over, reset the variable as true. So you can do a new poem."

    "Let's do a new poem! This time a Shakespearean sonnet."
    "When, in disgrace with fortune and men's eyes,\n I all alone beweep my outcast state."
    menu:
        "And trouble deaf heaven with my bootless..."
        "tears":
            $rhymes = False
        "cries":
            pass
    menu:
        "And look upon myself and curse my..."
        "fate":
            pass
        "life":
            $rhymes = False
    "Shakesperean poems are long so let's just end it there. What is the result?"

    if rhymes:
        "Hey look this poem rhymes, too!"
    else:
        "So...um...that poem didn't rhyme."
    $rhymes = True #resetting the variable
A Close Shave:
*Last Thing Done (Jul 10): Converted LiveComposite Sprites to LayeredImages
*Currently Doing: Trying to work out the transition thing for two character using the same sprite and try to figure out how to redo my multi-barber thing...i.e. see if there is a way to re_do my character callbacks
*First Next thing to do: Rebuild the project with the new RenPy (i.e. with gui.rpy present.), this will mean making some gui art now that I don't have access to the old theme.
*Next thing to do: Code in all the sprite emotion and camera movement for Close Shave Sprite Sections
*Other Thing to Do: Code in all CG and special animation stuff
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
TsukiWorks
Newbie
Posts: 5
Joined: Sat Jun 23, 2018 6:50 am
Projects: The Misunderstood
Deviantart: TsukiWorks
Contact:

Re: Error while running code

#10 Post by TsukiWorks » Thu Jul 12, 2018 1:22 pm

trooper6 wrote:
Thu Jul 12, 2018 12:40 pm
But it looks like you have lots and lots of these words...all of which lead to one of two responses. So I think there is a much better way of doing what you are aiming for.
So default is the value you give before the game starts.
Then you adjust the values as appropriate in the game.

You could do something just like this:

Code: Select all

default rhymes = True #Let's say that the poem defaults to rhyming.

## The game starts here.
label start:
    "Let's do our first poem--it's a limerick!"
    "The limerck packs laughs anatomical."
    menu:
        "Into space that is quite..."
        "economical":
            pass
        "small":
            $rhymes = False
    "But the good ones I've seen."
    menu:
        "So seldom are..."
        "finished":
            $rhymes = False
        "clean":
            pass
    menu:
        "And the clean ones so seldom are..."
        "comical":
            pass
        "funny":
            $rhymes = False

    if rhymes:
        "As expected from you...It's amazing! Wonder what could've given you so much inspiration...or who~."
    else:
        "Um...it's a nice poem, but your previous ones were better. Sorry..."
    $rhymes = True #Now the poem is over, reset the variable as true. So you can do a new poem."

    "Let's do a new poem! This time a Shakespearean sonnet."
    "When, in disgrace with fortune and men's eyes,\n I all alone beweep my outcast state."
    menu:
        "And trouble deaf heaven with my bootless..."
        "tears":
            $rhymes = False
        "cries":
            pass
    menu:
        "And look upon myself and curse my..."
        "fate":
            pass
        "life":
            $rhymes = False
    "Shakesperean poems are long so let's just end it there. What is the result?"

    if rhymes:
        "Hey look this poem rhymes, too!"
    else:
        "So...um...that poem didn't rhyme."
    $rhymes = True #resetting the variable
Thank you so, so much, but sadly, I still get that error saying that "light is not defined", when choosing the wrong words.

EDIT: Nevermind, fixed it...but now I have another error saying: "Tab characters are not allowed in Ren'Py scripts."
I checked the line again but I can't see that character...

EDIT #2: Fixed that too. Thank you so much again!

Post Reply

Who is online

Users browsing this forum: No registered users