I'm having some issues trying to implement a simple navigation system for my game. I've partially solved but I want to know what is wrong done in any case in order to understand how renpy works.
This is my goal: I want to have the current location of the player stored in a variable of the player object which always contains a string with the name of an screen, and everytime the user clicks on a navigation button just hide the current location screen, change the current location variable and show the 'new' current location screen with the new value. I've tried like this:
Code: Select all
init python:
class cl_player:
def __init__(self, fname, lname):
self.fname = fname
self.lname = lname
self.current_location = "home"
label start:
call create_player
label create_player:
$ player = cl_player("TestFirstName", "TestLastName")
return
imagebutton:
auto "gui/quick_map_%s.png"
action [Hide(player.current_location), SetVariable(player.current_location, "map"), Show(player.current_location),]
# Every location has obviously their own screen with modal True
I've tried to use a global variable instead of an object one, like this:
Code: Select all
label start:
$ current_location = "home"
imagebutton:
auto "gui/quick_map_%s.png"
action action [Hide(current_location), SetVariable("current_location", "map"), Show(current_location)]
Code: Select all
imagebutton:
auto "gui/quick_map_%s.png"
action action [Hide(current_location), SetVariable("current_location", "map"), Show("map")]
So, these are the two most imortant questions:
First one, Why in the first case the variable value change works on a global variable but not on an object one?
and, Second one, why in the second case the third action doesn't work as the variable value has not been changed?
I've already tried to other aproaches to solve the problem. The first one using a python action to change the player.current_position value:
Code: Select all
init python:
def setCurrentLocation(Location):
player.current_location = Location
imagebutton:
auto "gui/quick_map_%s.png"
action [Hide(player.current_location), Call(setCurrentLocation("map")), Show("map"),]
So, the third question: How I should use the python action? and most important, why is executed before clicking the button?
The third approach I've tried is using a renpy label:
Code: Select all
label setCurrentLocationLabel (loc):
$ player.current_location = loc
return "nothing"
imagebutton:
auto "gui/quick_map_%s.png"
action [Hide(player.current_location), Call("setCurrentLocationLabel", "map"), Show("map"),]
I could invert the action list like [Hide(player.current_location), Show("map"), Call("setCurrentLocationLabel", "map"),] and probably works but it's not like I want to do it, my goal was, hide, change and show in that especific order.
So, forth question, Do you see what I'm doing wrong here? It is posible to get back to the action list once you've called a label? Maybe is something related with the return clause?
I know is a large post, so thank you very much in advace