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')
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()
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