Python defines a name and later on, Ren'Py says it's 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
Potato0095
Regular
Posts: 84
Joined: Sun May 08, 2016 8:40 pm
Projects: LoveCraft
itch: potato95
Location: Brazil
Contact:

Python defines a name and later on, Ren'Py says it's not defined

#1 Post by Potato0095 »

I'm having some kind of problem in defining a name, because the script defines it, and later, Ren'Py says it's not defined.

Code: Select all

label gjconnect:
    scene blackbg onlayer background

    # If user is already connected, it asks if they want to logout.
    if persistent.GJusername != None:
        menu:
                "Disconnect from Game Jolt?"
                "Yes, disconnect.":
                    # Closes the session
                    python:
                        GJset.closeSession()
                        
                    # Cleaning persistent data
                    $ persistent.GJstatus = "disconnected"
                    $ persistent.GJusername = None
                    $ persistent.GJtoken = None
                    
                    # Renpy is too stupid to save these persistent data automatically so we must tell it to do it.
                    $ renpy.save_persistent()
                    
                    "Disconnected."
                    
                    # Returning to main menu. For some reason, renpy.MainMenu doesn't work anymore so we use this.
                    $ renpy.full_restart(transition=False, label='_invoke_main_menu', target='_main_menu')
                "No, return to menu.":
                    $ renpy.full_restart(transition=False, label='_invoke_main_menu', target='_main_menu')

    # If no user is connected, going to connect them
    else:

        # Asking for the username and token. Here, we use renpy.input, but other methods can be used.
        $ persistent.GJusername = renpy.input("Type here your username and press Enter.", "")
        $ persistent.GJtoken = renpy.input("Now, type here your game token and press Enter.", "")

        # Setting the init. For some random reason, this must be right here too.
        $ GJset = GameJoltTrophy(persistent.GJusername, persistent.GJtoken, persistent.GJGameKey, persistent.GJPrivateKey) # < -- GJset here is defined.

        python:
            GJset.changeUsername(persistent.GJusername)
            GJset.changeUserToken(persistent.GJtoken)
            GJcheck1 = GJset.authenticateUser()

        if GJcheck1 == True:
            # Authentication succesful, opening session.
            python:
                GJcheck2 = GJset.openSession()

            # Session succesfully opened
            if GJcheck2 == True:
                "Connection to Game Jolt succesful."

                # Says to the game that it's connected
                $ persistent.GJstatus = "connected"

                # Renpy is too stupid to save these persistent data automatically so we must tell it to do it.
                $ renpy.save_persistent()

                # Returning to main menu. For some reason, renpy.MainMenu doesn't work anymore so we use this.
                $ renpy.full_restart(transition=False, label='_invoke_main_menu', target='_main_menu')

            # If session couldn't open
            else:
                menu:
                    "A problem occured. Maybe your connection has a problem. Or maybe it's Game Jolt derping...\n\nTry again?"

                    # Retry to connect
                    "Yes, try again.":
                        jump gjconnect

                    # Give up
                    "No, return to menu.":
                        $ renpy.full_restart(transition=False, label='_invoke_main_menu', target='_main_menu')
Well, GJset is defined on python:

Code: Select all

$ GJset = GameJoltTrophy(persistent.GJusername, persistent.GJtoken, persistent.GJGameKey, persistent.GJPrivateKey)
~


When I try to disconnect, it needs to close the session on python too:

Code: Select all

$ GJset.closeSession()
The problem is this:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 63, in script
    $ GJset.closeSession()
  File "game/script.rpy", line 63, in <module>
    $ GJset.closeSession()
NameError: name 'GJset' is not defined
"There are two types of lies: Lies that hurt, and lies that don't."

philat
Eileen-Class Veteran
Posts: 1912
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Python defines a name and later on, Ren'Py says it's not defined

#2 Post by philat »

It should be defined prior to being accessed - I can't say more based on what you've shown.

User avatar
Potato0095
Regular
Posts: 84
Joined: Sun May 08, 2016 8:40 pm
Projects: LoveCraft
itch: potato95
Location: Brazil
Contact:

Re: Python defines a name and later on, Ren'Py says it's not defined

#3 Post by Potato0095 »

I found this here, I didn't change the code:
http://gamejolt.com/games/gamejoltapi-renpy/127112
I'm using the GUI btw.
"There are two types of lies: Lies that hurt, and lies that don't."

philat
Eileen-Class Veteran
Posts: 1912
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Python defines a name and later on, Ren'Py says it's not defined

#4 Post by philat »

Demo game seems to be working (insofar as GJset.open_session() works fine and boots me out to you're not connected part of the tester). If it's not working in your game, I would assume that you've made an error in importing it to your game. Go through the tester and your game again checking for GJset.

User avatar
Potato0095
Regular
Posts: 84
Joined: Sun May 08, 2016 8:40 pm
Projects: LoveCraft
itch: potato95
Location: Brazil
Contact:

Re: Python defines a name and later on, Ren'Py says it's not defined

#5 Post by Potato0095 »

I re-installed the demo just to be sure, when I open it, I already start logged in, so i logged out, made my login again without any problems, when I try to disconnect now Ren'Py gives me this:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 63, in script
    python:
  File "game/script.rpy", line 64, in <module>
    GJset.closeSession()
NameError: name 'GJset' is not defined

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

Full traceback:
  File "game/script.rpy", line 63, in script
    python:
  File "D:\Jogos\Gamejolt\gamejoltapi-renpy-127112\default-277948\data\GJAPI2-2.0-pc\renpy\ast.py", line 814, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "D:\Jogos\Gamejolt\gamejoltapi-renpy-127112\default-277948\data\GJAPI2-2.0-pc\renpy\python.py", line 1719, in py_exec_bytecode
    exec bytecode in globals, locals
  File "game/script.rpy", line 64, in <module>
    GJset.closeSession()
NameError: name 'GJset' is not defined

Windows-8-6.2.9200
Ren'Py 6.99.12.4.2187
GameJolt API Sample 2 2.0
The same thing as it did before.
"There are two types of lies: Lies that hurt, and lies that don't."

philat
Eileen-Class Veteran
Posts: 1912
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Python defines a name and later on, Ren'Py says it's not defined

#6 Post by philat »

Upon closer inspection, that is a terribly written demo on multiple levels and I'm really not interested in debugging it. (Example: Upon clicking the gamejolt icon to login and entering incorrect ID/PW, if you "Try again", persistent.GJusername is not None and therefore it tries to disconnect you -- facepalm). It's also REALLY slow -- the program hangs on checking whether I'm authenticated or not (when not logged in and just running the demo) for like 30 seconds. No offense, but peace out.

That said, try defining things in init, using default, or something or other, if you're really dedicated to making this work.

User avatar
Potato0095
Regular
Posts: 84
Joined: Sun May 08, 2016 8:40 pm
Projects: LoveCraft
itch: potato95
Location: Brazil
Contact:

Re: Python defines a name and later on, Ren'Py says it's not defined

#7 Post by Potato0095 »

Yeah, I'll think in something. That said, thank you for your help.
"There are two types of lies: Lies that hurt, and lies that don't."

Post Reply

Who is online

Users browsing this forum: No registered users