Page 1 of 1

Error while running code

Posted: Tue Jul 10, 2018 9:38 am
by TsukiWorks
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.

Re: Error while running code

Posted: Tue Jul 10, 2018 9:58 am
by Imperf3kt
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.

Re: Error while running code

Posted: Tue Jul 10, 2018 10:22 am
by TsukiWorks
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?

Re: Error while running code

Posted: Tue Jul 10, 2018 3:15 pm
by Imperf3kt
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.

Re: Error while running code

Posted: Tue Jul 10, 2018 3:42 pm
by trooper6
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.”

Re: Error while running code

Posted: Thu Jul 12, 2018 2:16 am
by TsukiWorks
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?

Re: Error while running code

Posted: Thu Jul 12, 2018 2:20 am
by trooper6
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).

Re: Error while running code

Posted: Thu Jul 12, 2018 11:35 am
by TsukiWorks
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..." 

Re: Error while running code

Posted: Thu Jul 12, 2018 12:40 pm
by trooper6
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

Re: Error while running code

Posted: Thu Jul 12, 2018 1:22 pm
by TsukiWorks
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!