Variables Referenced Before Assignment?

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
Kayotime
Regular
Posts: 37
Joined: Thu Jan 26, 2017 4:12 pm
Projects: Shinpaku High, Sakura Sunset
Location: America (US)
Contact:

Variables Referenced Before Assignment?

#1 Post by Kayotime »

Okay, the old post got buried so I'm reposting it here because I still need answers!

The link to the old post is here: viewtopic.php?p=466707#p466707

What I want to do is say that if "Koinu_Happy" equals "Koinu_Love" AND "Koinu_Excited" AND "Koinu_Brave" no matter what number on the -5 to 5 scale they are at, then "Koinu_Mood" equals "Neutral" and "Koinu_Status" equals "Meh..."

I think I may have fixed it based on what I was told:

Code: Select all

if Koinu_Happy == (Koinu_Love, Koinu_Excited, Koinu_Brave):
            
            Koinu_Mood = "Neutral"
            Koinu_Status = "Meh..."
From what I have been told, this SHOULD equal "if Koinu_Happy == Koinu_Love and Koinu_Happy == Koinu_Excited and Koinu_Happy == Koinu_Brave" which is pretty much what I wanted in the first place. Essentially, I want it to be so that whenever all four variables equal the same number, then "Koinu_Mood" is set to "Neutral" and "Koinu_Status" is set to "Meh..."

However, even after doing this, I still get the same exact error. I'm including the traceback.txt file.

This is what I have in the "moods.rpy" file, which is separate from all the other files for organizational purposes:

Code: Select all

## Demo allows me to quickly test the features without having to go through the whole intro. It has nothing to do with Koinu's Moods.
default Demo = True
default Gender = " "
default Name = " "
default Pref = " "
default Pass = " "
    
default Koinu = "????"
default Koi_Rep = 0
default Koinu_Pref = "Straight"
default Koi_XP = 3
default Koi_XN = 0

default Koinu_Happy = 0
default Koinu_Love = 0
default Koinu_Excited = 0
default Koinu_Brave = 0

default Koinu_Mood = " "
default Koinu_Status = " "

init python:
    
    def set_status():
        global Koinu_Mood, Koinu_Status
        global Koinu_Happy, Koinu_Love, Koinu_Excited, Koinu_Brave
        
        if Koinu_Happy == (Koinu_Love, Koinu_Excited, Koinu_Brave):
            
            Koinu_Mood = "Neutral"
            Koinu_Status = "Meh..."

        elif Koinu_Happy > 0 and Koinu_Happy > (Koinu_Love, Koinu_Excited, Koinu_Brave):
        
            if Koinu_Happy == 1:
            
                Koinu_Mood = "Pleased"
                Koinu_Status = "Well enough."
            
            elif Koinu_Happy == 2:
            
                Koinu_Mood = "Content"
                Koinu_Status = "Pretty good!"
            
            elif Koinu_Happy == 3:
            
                Koinu_Mood = "Happy"
                Koinu_Status = "Happily smiling!"
            
            elif Koinu_Happy == 4:
            
                Koinu_Mood = "Delighted"
                Koinu_Status = "LOL! ^w^"
            
            elif Koinu_Happy == 5:
            
                Koinu_Mood = "Ecstatic"
                Koinu_Status = "AWESOME SAUCE!!"
            
            elif Koinu_Happy > 5:
            
                Koinu_Happy = 5
                Koinu_Mood = "Ecstatic"
                Koinu_Status = "AWESOME SAUCE!!"
            
        elif Koinu_Happy < 0 and Koinu_Happy < (Koinu_Love, Koinu_Excited, Koinu_Brave):
        
            if Koinu_Happy == -1:
            
                Koinu_Mood = "Gloomy"
                Koinu_Status = "A little blue..."
            
            elif Koinu_Happy == -2:
            
                Koinu_Mood = "Hurt"
                Koinu_Status = "Hurting..."
            
            elif Koinu_Happy == -3:
            
                Koinu_Mood = "Sad"
                Koinu_Status = "Down in the dumps..."
            
            elif Koinu_Happy == -4:
            
                Koinu_Mood = "Forlorn"
                Koinu_Status = "About to cry..."
            
            elif Koinu_Happy == -5:
            
                Koinu_Mood = "Depressed"
                Koinu_Status = "Just kill me now..."
            
            elif Koinu_Happy < -5:
            
                Koinu_Happy = -5
                Koinu_Mood = "Depressed"
                Koinu_Status = "Just kill me now..."
            
        elif Koinu_Love > 0 and Koinu_Love > (Koinu_Happy, Koinu_Excited, Koinu_Brave):
        
            if Koinu_Love == 1:
            
                Koinu_Mood = "Flirty"
                Koinu_Status = "She's pretty cute..."
            
            elif Koinu_Love == 2:
            
                Koinu_Mood = "Affectionate"
                Koinu_Status = "Give me a hug!"
            
            elif Koinu_Love == 3:
            
                Koinu_Mood = "Romantic"
                Koinu_Status = "I think I'm in love!"
            
            elif Koinu_Love == 4:
            
                Koinu_Mood = "Alluring"
                Koinu_Status = "Give me a kiss!"
            
            elif Koinu_Love == 5:
            
                Koinu_Mood = "Irresistable"
                Koinu_Status = "Let's go back to my place! ♥‿♥"
            
            elif Koinu_Love > 5:
            
                Koinu_Love = 5
                Koinu_Mood = "Irresistable"
                Koinu_Status = "Let's go back to my place! ♥‿♥"
            
        elif Koinu_Love < 0 and Koinu_Love < (Koinu_Happy, Koinu_Excited, Koinu_Brave):
        
            if Koinu_Love == -1:
            
                Koinu_Mood = "Annoyed"
                Koinu_Status = "Grrr..."
            
            elif Koinu_Love == -2:
            
                Koinu_Mood = "Irritated"
                Koinu_Status = "Stop bugging me!"
            
            elif Koinu_Love == -3:
            
                Koinu_Mood = "Angry"
                Koinu_Status = "Go away!"
            
            elif Koinu_Love == -4:
            
                Koinu_Mood = "Furious"
                Koinu_Status = "Leave me alone!!!"
            
            elif Koinu_Love == -5:
            
                Koinu_Mood = "Livid"
                Koinu_Status = "I hate you!"
            
            elif Koinu_Love < -5:
            
                Koinu_Love = -5
                Koinu_Mood = "Livid"
                Koinu_Status = "I hate you!"
            
        elif Koinu_Excited > 0 and Koinu_Excited > (Koinu_Happy, Koinu_Love, Koinu_Brave):
        
            if Koinu_Excited == 1:
            
                Koinu_Mood = "Eager"
                Koinu_Status = "Let's go!"
            
            elif Koinu_Excited == 2:
            
                Koinu_Mood = "Perky"
                Koinu_Status = "Come on, come on, move it!"
            
            elif Koinu_Excited == 3:
            
                Koinu_Mood = "Excited"
                Koinu_Status = "Can't you keep up? Come on!"
            
            elif Koinu_Excited == 4:
            
                Koinu_Mood = "Restless"
                Koinu_Status = "I can't sit still! Let's GO!"
            
            elif Koinu_Excited == 5:
            
                Koinu_Mood = "Hyperactive"
                Koinu_Status = "Hyper, hyper, HYPEEEEEERRRRR!!!"
            
            elif Koinu_Excited > 5:
            
                Koinu_Excited = 5
                Koinu_Mood = "Hyperactive"
                Koinu_Status = "Hyper, hyper, HYPEEEEEERRRRR!!!"
            
        elif Koinu_Excited < 0 and Koinu_Excited < (Koinu_Happy, Koinu_Love, Koinu_Brave):
        
            if Koinu_Excited == -1:
            
                Koinu_Mood = "Bored"
                Koinu_Status = "This is boring...."
            
            elif Koinu_Excited == -2:
            
                Koinu_Mood = "Lazy"
                Koinu_Status = "Wake me when I care..."
            
            elif Koinu_Excited == -3:
            
                Koinu_Mood = "Tired"
                Koinu_Status = "*YAWN!* Oh, sorry... I'm just... tired."
            
            elif Koinu_Excited == -4:
            
                Koinu_Mood = "Exhausted"
                Koinu_Status = "Can't... take... another... step... ugh..."
            
            elif Koinu_Excited == -5:
            
                Koinu_Mood = "Lethargic"
                Koinu_Status = "ZZZZZzzzzz..."
            
            elif Koinu_Excited < -5:
            
                Koinu_Excited = -5
                Koinu_Mood = "Lethargic"
                Koinu_Status = "ZZZZZzzzzz..."
            
        elif Koinu_Brave > 0 and Koinu_Brave > (Koinu_Happy, Koinu_Love, Koinu_Excited):
        
            if Koinu_Brave == 1:
            
                Koinu_Mood = "Curious"
                Koinu_Status = "Oooo! What's that?!"
            
            elif Koinu_Brave == 2:
            
                Koinu_Mood = "Inspired"
                Koinu_Status = "Let's go do it!"
            
            elif Koinu_Brave == 3:
            
                Koinu_Mood = "Brave"
                Koinu_Status = "I'm not afraid! Come at me!"
            
            elif Koinu_Brave == 4:
            
                Koinu_Mood = "Determined"
                Koinu_Status = "I will never back down!"
            
            elif Koinu_Brave == 5:
            
                Koinu_Mood = "Heroic"
                Koinu_Status = "I'll save you! You're safe with me!"
            
            elif Koinu_Brave > 5:
            
                Koinu_Brave = 5
                Koinu_Mood = "Heroic"
                Koinu_Status = "I'll save you! You're safe with me!"
            
        elif Koinu_Brave < 0 and Koinu_Brave < (Koinu_Happy, Koinu_Love, Koinu_Excited):
        
            if Koinu_Brave == -1:
            
                Koinu_Mood = "Timid"
                Koinu_Status = "Wh-what? Uhmm...."
            
            elif Koinu_Brave == -2:
            
                Koinu_Mood = "Startled"
                Koinu_Status = "AH! Wh-what?! N-No!"
            
            elif Koinu_Brave == -3:
            
                Koinu_Mood = "Scared"
                Koinu_Status = "AHHH! STAY AWAY FROM ME!!"
            
            elif Koinu_Brave == -4:
            
                Koinu_Mood = "Terrified"
                Koinu_Status = "HEEEEEEEEEELP!"
            
            elif Koinu_Brave == -5:
            
                Koinu_Mood = "Traumatized"
                Koinu_Status = "............. AAAAAAAAAAHHHHHHHHHHHH!"
            
            elif Koinu_Brave < -5:
            
                Koinu_Brave = -5
                Koinu_Mood = "Traumatized"
                Koinu_Status = "............. AAAAAAAAAAHHHHHHHHHHHH!"
This is what I have in the "screens.rpy" file, in order to have the function called every time an option is clicked:

Code: Select all

## Choice screen ###############################################################
##
## This screen is used to display the in-game choices presented by the menu
## statement. The one parameter, items, is a list of objects, each with caption
## and action fields.
##
## http://www.renpy.org/doc/html/screen_special.html#choice

## This is what I was told to put in the previous post.

screen choice(items):
    style_prefix "choice"

    vbox:
        for i in items:
            textbutton i.caption action [Function(set_status), i.action]
And yet, I still get the error as shown in the "traceback.txt" file.

Here is a little walkthrough of what happens in the game with all the scripting set to what I've already shown you:

1. I run the test.
2. The main menu comes up without a problem.
3. I click "Start".
4. The game starts without a problem.
5. The first set of menu options come up with the dialogue prompt. No problems.
6. I click on either menu choice. Doesn't matter which one.
7. Before the menu choice takes me where it is coded to go to, the game crashes and I get the error.
8. Error is "Koinu_Happy referenced before assignment." I have no idea what that means.
9. I close the game and take a look at the code. I'm too inexperienced to see a problem.
10. I come here looking for answers. :(

Please help me!
Attachments
traceback.txt
The "traceback.txt" file.
(3.22 KiB) Downloaded 68 times
Active Project: Sakura Sunset
NOTICE: Shinpaku High is being put on hold for now. Sorry for the inconvenience!
Thank You!

User avatar
RicharDann
Veteran
Posts: 286
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: Variables Referenced Before Assignment?

#2 Post by RicharDann »

I've copied your code to a new project and I've been testing it for a while, and it hasn't given me any errors. Are you sure you placed the variable asignments (with default) in the same mood.rpy file and just before the init python block? Maybe the problem is in the script or in the menu itself, traceback points to a prologue.rpy file, wich you didn't post here.

One change you probably want to make is this line:

Code: Select all

        if Koinu_Happy == (Koinu_Love, Koinu_Excited, Koinu_Brave):        
It's comparing the value in Koinu_Happy, wich is 0, to a tuple of (Koinu_Love, Koinu_Excited, Koinu_Brave), a tuple is different from 0 so it won't work. This is how it could work:

Code: Select all

        if Koinu_Happy == Koinu_Love and Koinu_Happy == Koinu_Excited and Koinu_Happy == Koinu_Brave:


This way it compares each variable to Koinu_Happy, and if all of them are equal, then it executes the code below (setting mood to 'Neutral' and status to 'Meh...')

If you're going for this approach you should change each of the other comparisons after this first one to use and, or, and other operators and compare each variable the way I described, you can't compare a single variable to a group of variables unless you use more advanced functions like all().

Just in case, I'll attach the project I used to test this.
Koinu.rar
(697.62 KiB) Downloaded 17 times
The most important step is always the next one.

User avatar
Kayotime
Regular
Posts: 37
Joined: Thu Jan 26, 2017 4:12 pm
Projects: Shinpaku High, Sakura Sunset
Location: America (US)
Contact:

Re: Variables Referenced Before Assignment?

#3 Post by Kayotime »

(Okay well that just gave me a lot of work to do that I was trying to avoid but if there really isn't any other way then...)

*smiles*

Thanks for the help!

If it still gives me problems after changing all that code, then I'll put a new post here which includes the "prologue.rpy" file. That is another file I didn't think was involved, which contains the start of the game where the player creates their character.

Will keep you posted!

*runs off to change huge amounts of code*
Active Project: Sakura Sunset
NOTICE: Shinpaku High is being put on hold for now. Sorry for the inconvenience!
Thank You!

User avatar
RicharDann
Veteran
Posts: 286
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: Variables Referenced Before Assignment?

#4 Post by RicharDann »

Ah, I'm late, I came up with a way to use all() function so you just had to adjust your code a little instead of having to struggle with all those ands, I don't know if you'll be able to use it for this case but here it goes:

Code: Select all

if all(Koinu_Happy == x for x in (Koinu_Love, Koinu_Excited, Koinu_Brave)):
This should have the same effect as the code I mentioned earlier, but it might be a little hard to understand right off the bat. It's basically doing what you wanted in the first place with your original code, but with a correct syntax.
The most important step is always the next one.

User avatar
Kayotime
Regular
Posts: 37
Joined: Thu Jan 26, 2017 4:12 pm
Projects: Shinpaku High, Sakura Sunset
Location: America (US)
Contact:

Re: Variables Referenced Before Assignment?

#5 Post by Kayotime »

Ah, well, thanks for getting to me before I even started changing things! :)

So "x" would equal what? Or do I just put in "x" exactly as it is? I just need to make sure before I go messing around with it, heh.
Active Project: Sakura Sunset
NOTICE: Shinpaku High is being put on hold for now. Sorry for the inconvenience!
Thank You!

User avatar
Kayotime
Regular
Posts: 37
Joined: Thu Jan 26, 2017 4:12 pm
Projects: Shinpaku High, Sakura Sunset
Location: America (US)
Contact:

Re: Variables Referenced Before Assignment?

#6 Post by Kayotime »

Okay here's what I did:

From the "moods.rpy" file:

Code: Select all

## This is how it is organized, exactly the way it is in the code.
## These variables are here for temporary storage until I can organize them.
## They have no effect on the moods.

default Demo = False
default Gender = " "
default Name = " "
default Pref = " "
default Pass = " "
    
default Koinu = "????"
default Koi_Rep = 0
default Koinu_Pref = "Straight"
default Koi_XP = 3
default Koi_XN = 0

## These are the important variables for the moods.

default Koinu_Happy = 0
default Koinu_Love = 0
default Koinu_Excited = 0
default Koinu_Brave = 0

default Koinu_Mood = " "
default Koinu_Status = " "

## This is the beginning of the python code for the moods.

init python:
    
    def set_status():
        global Koinu_Mood, Koinu_Status
        global Koinu_Happy, Koinu_Love, Koinu_Excited, Koinu_Brave
        
        ## This is what you told me to put.
        
        if all(Koinu_Happy == x for x in (Koinu_Love, Koinu_Excited, Koinu_Brave)):
            
            Koinu_Mood = "Neutral"
            Koinu_Status = "Meh..."
            
            ## Trying it with the other sequences...
            
        elif Koinu_Happy > 0 and all(Koinu_Happy > x for x in (Koinu_Love, Koinu_Excited, Koinu_Brave)):
        
            if Koinu_Happy == 1:
            
                Koinu_Mood = "Pleased"
                Koinu_Status = "Well enough."
            
            elif Koinu_Happy == 2:
            
                Koinu_Mood = "Content"
                Koinu_Status = "Pretty good!"
            
            elif Koinu_Happy == 3:
            
                Koinu_Mood = "Happy"
                Koinu_Status = "Happily smiling!"
            
            elif Koinu_Happy == 4:
            
                Koinu_Mood = "Delighted"
                Koinu_Status = "LOL! ^w^"
            
            elif Koinu_Happy == 5:
            
                Koinu_Mood = "Ecstatic"
                Koinu_Status = "AWESOME SAUCE!!"
            
            elif Koinu_Happy > 5:
            
                Koinu_Happy = 5
                Koinu_Mood = "Ecstatic"
                Koinu_Status = "AWESOME SAUCE!!"
            
        elif Koinu_Happy < 0 and all(Koinu_Happy < x for x in (Koinu_Love, Koinu_Excited, Koinu_Brave)):
        
            if Koinu_Happy == -1:
            
                Koinu_Mood = "Gloomy"
                Koinu_Status = "A little blue..."
            
            elif Koinu_Happy == -2:
            
                Koinu_Mood = "Hurt"
                Koinu_Status = "Hurting..."
            
            elif Koinu_Happy == -3:
            
                Koinu_Mood = "Sad"
                Koinu_Status = "Down in the dumps..."
            
            elif Koinu_Happy == -4:
            
                Koinu_Mood = "Forlorn"
                Koinu_Status = "About to cry..."
            
            elif Koinu_Happy == -5:
            
                Koinu_Mood = "Depressed"
                Koinu_Status = "Just kill me now..."
            
            elif Koinu_Happy < -5:
            
                Koinu_Happy = -5
                Koinu_Mood = "Depressed"
                Koinu_Status = "Just kill me now..."
            
        elif Koinu_Love > 0 and all(Koinu_Love > x for x in (Koinu_Happy, Koinu_Excited, Koinu_Brave)):
        
            if Koinu_Love == 1:
            
                Koinu_Mood = "Flirty"
                Koinu_Status = "She's pretty cute..."
            
            elif Koinu_Love == 2:
            
                Koinu_Mood = "Affectionate"
                Koinu_Status = "Give me a hug!"
            
            elif Koinu_Love == 3:
            
                Koinu_Mood = "Romantic"
                Koinu_Status = "I think I'm in love!"
            
            elif Koinu_Love == 4:
            
                Koinu_Mood = "Alluring"
                Koinu_Status = "Give me a kiss!"
            
            elif Koinu_Love == 5:
            
                Koinu_Mood = "Irresistable"
                Koinu_Status = "Let's go back to my place! ♥‿♥"
            
            elif Koinu_Love > 5:
            
                Koinu_Love = 5
                Koinu_Mood = "Irresistable"
                Koinu_Status = "Let's go back to my place! ♥‿♥"
            
        elif Koinu_Love < 0 and all(Koinu_Love < x for x in (Koinu_Happy, Koinu_Excited, Koinu_Brave)):
        
            if Koinu_Love == -1:
            
                Koinu_Mood = "Annoyed"
                Koinu_Status = "Grrr..."
            
            elif Koinu_Love == -2:
            
                Koinu_Mood = "Irritated"
                Koinu_Status = "Stop bugging me!"
            
            elif Koinu_Love == -3:
            
                Koinu_Mood = "Angry"
                Koinu_Status = "Go away!"
            
            elif Koinu_Love == -4:
            
                Koinu_Mood = "Furious"
                Koinu_Status = "Leave me alone!!!"
            
            elif Koinu_Love == -5:
            
                Koinu_Mood = "Livid"
                Koinu_Status = "I hate you!"
            
            elif Koinu_Love < -5:
            
                Koinu_Love = -5
                Koinu_Mood = "Livid"
                Koinu_Status = "I hate you!"
            
        elif Koinu_Excited > 0 and all(Koinu_Excited > x for x in (Koinu_Happy, Koinu_Love, Koinu_Brave)):
        
            if Koinu_Excited == 1:
            
                Koinu_Mood = "Eager"
                Koinu_Status = "Let's go!"
            
            elif Koinu_Excited == 2:
            
                Koinu_Mood = "Perky"
                Koinu_Status = "Come on, come on, move it!"
            
            elif Koinu_Excited == 3:
            
                Koinu_Mood = "Excited"
                Koinu_Status = "Can't you keep up? Come on!"
            
            elif Koinu_Excited == 4:
            
                Koinu_Mood = "Restless"
                Koinu_Status = "I can't sit still! Let's GO!"
            
            elif Koinu_Excited == 5:
            
                Koinu_Mood = "Hyperactive"
                Koinu_Status = "Hyper, hyper, HYPEEEEEERRRRR!!!"
            
            elif Koinu_Excited > 5:
            
                Koinu_Excited = 5
                Koinu_Mood = "Hyperactive"
                Koinu_Status = "Hyper, hyper, HYPEEEEEERRRRR!!!"
            
        elif Koinu_Excited < 0 and all(Koinu_Excited < x for x in (Koinu_Happy, Koinu_Love, Koinu_Brave)):
        
            if Koinu_Excited == -1:
            
                Koinu_Mood = "Bored"
                Koinu_Status = "This is boring...."
            
            elif Koinu_Excited == -2:
            
                Koinu_Mood = "Lazy"
                Koinu_Status = "Wake me when I care..."
            
            elif Koinu_Excited == -3:
            
                Koinu_Mood = "Tired"
                Koinu_Status = "*YAWN!* Oh, sorry... I'm just... tired."
            
            elif Koinu_Excited == -4:
            
                Koinu_Mood = "Exhausted"
                Koinu_Status = "Can't... take... another... step... ugh..."
            
            elif Koinu_Excited == -5:
            
                Koinu_Mood = "Lethargic"
                Koinu_Status = "ZZZZZzzzzz..."
            
            elif Koinu_Excited < -5:
            
                Koinu_Excited = -5
                Koinu_Mood = "Lethargic"
                Koinu_Status = "ZZZZZzzzzz..."
            
        elif Koinu_Brave > 0 and all(Koinu_Brave > x for x in (Koinu_Happy, Koinu_Love, Koinu_Excited)):
        
            if Koinu_Brave == 1:
            
                Koinu_Mood = "Curious"
                Koinu_Status = "Oooo! What's that?!"
            
            elif Koinu_Brave == 2:
            
                Koinu_Mood = "Inspired"
                Koinu_Status = "Let's go do it!"
            
            elif Koinu_Brave == 3:
            
                Koinu_Mood = "Brave"
                Koinu_Status = "I'm not afraid! Come at me!"
            
            elif Koinu_Brave == 4:
            
                Koinu_Mood = "Determined"
                Koinu_Status = "I will never back down!"
            
            elif Koinu_Brave == 5:
            
                Koinu_Mood = "Heroic"
                Koinu_Status = "I'll save you! You're safe with me!"
            
            elif Koinu_Brave > 5:
            
                Koinu_Brave = 5
                Koinu_Mood = "Heroic"
                Koinu_Status = "I'll save you! You're safe with me!"
            
        elif Koinu_Brave < 0 and all(Koinu_Brave < x for x in (Koinu_Happy, Koinu_Love, Koinu_Excited)):
        
            if Koinu_Brave == -1:
            
                Koinu_Mood = "Timid"
                Koinu_Status = "Wh-what? Uhmm...."
            
            elif Koinu_Brave == -2:
            
                Koinu_Mood = "Startled"
                Koinu_Status = "AH! Wh-what?! N-No!"
            
            elif Koinu_Brave == -3:
            
                Koinu_Mood = "Scared"
                Koinu_Status = "AHHH! STAY AWAY FROM ME!!"
            
            elif Koinu_Brave == -4:
            
                Koinu_Mood = "Terrified"
                Koinu_Status = "HEEEEEEEEEELP!"
            
            elif Koinu_Brave == -5:
            
                Koinu_Mood = "Traumatized"
                Koinu_Status = "............. AAAAAAAAAAHHHHHHHHHHHH!"
            
            elif Koinu_Brave < -5:
            
                Koinu_Brave = -5
                Koinu_Mood = "Traumatized"
                Koinu_Status = "............. AAAAAAAAAAHHHHHHHHHHHH!"
                
## I tested it and...
## I still get the error...
## What am I doing wrong?
From the "prologue.rpy" file:

Code: Select all

## This starts the actual game.

label start:
    
    ## This allows me to quickly test the date functions.
    ## Has worked before, no problems.
    
    if Demo == True:
        $ Name = "Tori-Chan"
        $ Gender = "Female"
        $ Pref = "Straight"
        jump demo
    
        ## The first set of choices.
        ## The intro isn't done yet.
        ## "Play the intro" creates an error.
        ## This is normal, considering the intro isn't done.
        ## "Skip the intro" is the only one that works.
        ## As a link, "Skip the intro" cause the function in "moods.rpy" to be called.
        ## This is where the error pops up.
        ## After testing...
        ## Still get the error...
        
    menu:
        
        "What would you like to do?"
        
        "Play the intro.":
            
            jump intro
            
        "Skip the intro.":
            
            jump char
            
            ## Everything after this has worked perfectly before, but only if I remove the call statement thing from "screens.rpy"
From the "screens.rpy" file:

Code: Select all

## Choice screen ###############################################################
##
## This screen is used to display the in-game choices presented by the menu
## statement. The one parameter, items, is a list of objects, each with caption
## and action fields.
##
## http://www.renpy.org/doc/html/screen_special.html#choice

## This is what I was told to put.
## Seems to work, since the error is called when I click a choice...
## No other settings have been changed in the "screens.rpy" file.
## After testing...
## Still get the error...

screen choice(items):
    style_prefix "choice"

    vbox:
        for i in items:
            textbutton i.caption action [Function(set_status), i.action]
Help?
Active Project: Sakura Sunset
NOTICE: Shinpaku High is being put on hold for now. Sorry for the inconvenience!
Thank You!

User avatar
RicharDann
Veteran
Posts: 286
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: Variables Referenced Before Assignment?

#7 Post by RicharDann »

This whole expression:

Code: Select all

all(Koinu_Happy == x for x in (Koinu_Love, Koinu_Excited, Koinu_Brave))
Means something like:
"Check If Koinu_Happy is equal to x, and for each of the values in tuple (Koinu_Love, Koinu_Excited, Koinu_Brave), check if they are equal to x, if they are, then Koinu_Happy and all of those values are equal, so return True. If not, return False"

x is just a placeholder variable, it could be a number, or anything, but the program figures out that if you put x, or any variable, it should simply compare all the variables and return the result of that comparison. Hope that made sense.

This "Variable referenced before assignment" error, from my experience, relates to a global variable not being declared using default, or being declared in an improper way or somewhere inside a label, but your code is correctly written and placed.

I tested your updated code on a brand new project and it's working, I've even tried changing the mood variable using choices and it seems to be updated properly. I'm not really sure what could be causing the problem. It could be because you're trying to start the game from a prologue.rpy file instead of the default script.rpy file, but I erased mine and it still works.

Try deleting persistent data for your project from the Ren'Py Launcher, then try again starting a new game, or create a new project and copy all the files there (the .rpy files, not the .rpyc), and see if the problem persists.

I'll upload my test project here once again, just in case. Bear in mind it has a lot of test code, the intro label includes a debug screen I used to test the different mood changes. Overall your function seems to be working fine.
game.rar
(471.63 KiB) Downloaded 14 times
The most important step is always the next one.

User avatar
Kayotime
Regular
Posts: 37
Joined: Thu Jan 26, 2017 4:12 pm
Projects: Shinpaku High, Sakura Sunset
Location: America (US)
Contact:

Re: Variables Referenced Before Assignment?

#8 Post by Kayotime »

Okay, let me try that then...

Sorry for being so confused. I'm new to coding, but I really liked Ren'Py games such as "Long Live The Queen" so I wanted to make my own. I hope I'm not being too much of a bother. I'll get back to you after making the adjustments.
Active Project: Sakura Sunset
NOTICE: Shinpaku High is being put on hold for now. Sorry for the inconvenience!
Thank You!

Post Reply

Who is online

Users browsing this forum: Google [Bot], Sugar_and_rice, voluorem