In my game, the player can create a mini city like in the Travian Game (he clicks on an area and decides which building he wants build). You have an imagemap with some hotspot. When you click on them, it opens a a screen listing some buildings you can build (as image button). Click on a building and it appears on the chosen hotspot. When you click on the building, this one open a new screen listing all the informations about the building.
I wrote a code which has no issues when we start a new game, but when we save the game and reload it, nothing works... I use the => on "show" action Function(renpy.retain_after_load) in the village_screen to save the localization of each buildings. But when I reload the game, all the images of the buildings have sometimes disappeared or when we click on it, it doesn't work. How can I save and reload the game without issues ?
Code: Select all
init python:
class Place:
places = [] # contains all the instantiated places..
def __init__(self, img, loc, panel = 0):
self.img = img
self.loc = loc
self.panel = panel
self.places.append(self) # append the created place in the places class attrib...
class Building:
def __init__(self, name, img, loc = 0, timeleft = 0, time_build = 0):
self.name = name
self.img = img
self.timeleft = timeleft
self.time_build = time_build
Building.loc = loc
@classmethod
def attribution(cls, building_image):
for place in Place.places: # reference the places then loop through it...
if place.loc == cls.loc:
Place.places[Place.places.index(place)].img = building_image
def change_loc(attribute, coordonate):
Building.loc = coordonate
def open_panel(panel_value): ## Let opens the screen of each building
for i in Place.places:
if i.loc == panel_value:
Place.places[Place.places.index(i)].panel = 1
for j in Place.places:
if j.img != None and j.panel == 1:
Place.places[Place.places.index(j)].panel = 0
if Place.places[Place.places.index(j)].img == "images/house.png":
renpy.show_screen("house_screen")
elif Place.places[Place.places.index(j)].img == "images/military_house.png":
renpy.show_screen("military_screen")
elif Place.places[Place.places.index(j)].img == "images/forum.png":
renpy.show_screen("forum_screen")
default place01 = Place("", 1)
default place02 = Place("", 2)
default place03 = Place("", 3)
define building01 = Building("House","images/house.png")
define building02 = Building("Forum","images/forum.png")
define building03 = Building("Military house","images/military_house.png")
## All the screens
screen village_screen: ## This screen contains the hotspots where we can build the buildings
on "show" action Function(renpy.retain_after_load)
zorder 3
imagemap:
idle "images/village_background.png"
if place01.img == "":
hotspot (545,250,205,198) clicked [Show("constructable_buildings_screen"), Function(change_loc, building01.loc, place01.loc)]
else:
imagebutton:
focus_mask True
idle place01.img
xalign 0.3
yalign 0.20
action Function(open_panel, place01.loc) #When I click on imageboutton, nothing happen
if place02.img == "":
hotspot (529,508,216,147) clicked [Show("constructable_buildings_screen"), Function(change_loc, building01.loc, place02.loc)]
else:
imagebutton:
focus_mask True
idle place02.img
xalign 0.3
yalign 0.50
action Function(open_panel, place02.loc)
if place03.img == "":
hotspot (761,649,185,104) clicked [Show("constructable_buildings_screen"), Function(change_loc, building01.loc, place03.loc)]
else:
imagebutton:
focus_mask True
idle place03.img
xalign 0.45
yalign 0.60
action Function(open_panel, place03.loc)
screen constructable_buildings_screen: ## This screen lists all the building that the player can create. If he clicks on a building (imagebutton) this one is build on the choosen hotspot
zorder 4
vbox:
xalign 0.5
yalign 0.5
add "images/bg_select_screen.png"
vbox:
xalign 0.5
yalign 0.5
imagebutton: #After load, When I click on imageboutton, nothing happens. Same for all the imagebuttons of the screen
focus_mask True
idle building01.img
action Function(Building.attribution, building01.img)
imagebutton:
focus_mask True
idle building02.img
action Function(Building.attribution, building02.img)
imagebutton:
focus_mask True
idle building03.img
action Function(Building.attribution, building03.img)
hbox:
xalign 0.5
yalign 0.8
textbutton "Quitter" action [Hide("constructable_buildings_screen")]
screen house_screen: #When we click on a building, the associated panel is open. But after load, when I click on the building, nothing happens...
zorder 4
vbox:
xalign 0.5
yalign 0.5
add "images/bg_building_menu_screen.png"
vbox:
xalign 0.5
yalign 0.5
text "You are in a [building01.name]"
textbutton "Quit" action Hide("house_screen")
screen forum_screen: #When we click on a building, the associated panel is open. But after load, when I click on the building, nothing happens...
zorder 4
vbox:
xalign 0.5
yalign 0.5
add "images/bg_building_menu_screen.png"
vbox:
xalign 0.5
yalign 0.5
text "You are in a [building02.name]"
textbutton "Quit" action Hide("forum_screen")
screen military_screen: #When we click on a building, the associated panel is open. But after load, when I click on the building, nothing happens...
zorder 4
vbox:
xalign 0.5
yalign 0.5
add "images/bg_building_menu_screen.png"
vbox:
xalign 0.5
yalign 0.5
text "You are in a [building03.name]"
textbutton "Quit" action Hide("military_screen")
screen modal_screen:
zorder 1
add "#000"
modal True
# The game starts here.
label start:
show screen village_screen
show screen debug_screen
show screen modal_screen
"You've created a new Ren'Py game."
return