The way it's supposed to work is I have a Locations class which contains information about the area, a list of random encounters that can occur, if the area has been discovered, etc.
I have a default variable map_point that contains the current location and gets updated whenever the player travels.
I have the map_point display the current location name on the screen. This continues to display the correct location on load, however when trying to travel everything just breaks, but only breaks if the game was loaded. If you never save and load the map runs fine.
Is there anyway to force variables to save and load correctly? Or is there a better way to be handling this sort of a system?
I know this is extremely vague but if anyone has any suggestions or has done a travel system and could direct me to it I'd really appreciate it.
Code: Select all
class Location:
def __init__(self,img,bg_day,bg_night,x,y,name,_scene,scav,explore,encounter,hostility,discovered):
# Image is the map icon used
# bg is the background image to use while in this location
# Name is a string containing the location name
# scene is a string containing the default scene label for this location
# Scav is a list of lists containing potential encounters and the chance of that encounter that can be discovered while scavanging
# Explore is a list of potential lists containing encounters found while exploring as well as a list of potential connections that can be discovered, each with a weight associated with them
## Each Scavenge or Explore is made of a list (Encounter_scene, Encounter_chance, Weather, Season, Hour_begin, Hour_end)
# Encounter contains a list of hostile encounters that can be encountered
# Each encounter contains the Mob,
# Connections is a list of tuples containing other locations that directly connect to this location and the time required to travel
## Connections (location,hours,minutes)
# Discovered is a boolean that determines if the location has been discovered or not
self.img = img
self.bg_day = bg_day
self.bg_night = bg_night
self.x = x
self.y = y
self.name = name
self._scene = _scene
self.scavenge = scav
self.explore = explore
self.encounter = encounter
self.hostility = hostility
self.discovered = discovered
Code: Select all
def travel(_start,_destination):
_path = None
for _r in roads:
if (_r.locale_1 == _start or _r.locale_2 == _start) and (_r.locale_1 == _destination or _r.locale_2 == _destination):
_path = _r
store.map_point = _destination
store.selected_locale = None
# Check for encounters
# Update time
_t = renpy.random.randint(_path.tt_minutes - _path.tt_var,_path.tt_minutes + _path.tt_var)
add_time(0,_t)
renpy.jump(map_point._scene)
# Reset Variables
Map Screen, displays locations and roads available. Clicking on a location highlights it and clicking again triggers the travel function
Code: Select all
screen map():
modal True
zorder 50
add "gui/rooms/worldmap.jpg"
# Menubar
fixed:
pos (909,8)
xysize (355,80)
imagebutton auto "gui/button/exitbutton_%s.png" action [Hide("map"),Show("menubar")] area (279,0,80,80) anchor (0.5,0.5) focus_mask "gui/button/button_mask.png"
# Map Details
for _i in range(len(roads)):
if roads[_i].discovered and roads[_i].locale_1.discovered and roads[_i].locale_2.discovered:
$ _dis_a = roads[_i].locale_1.x - roads[_i].locale_2.x
if _dis_a < 0:
$ _dis_a *= -1
$ _dis_b = roads[_i].locale_1.y - roads[_i].locale_2.y
if _dis_b < 0:
$ _dis_b *= -1
$ _points = int(math.sqrt((_dis_a * _dis_a) + (_dis_b * _dis_b))/12)
# Draw Paths from current location
for _o in range(_points):
if (roads[_i].locale_1 == map_point or roads[_i].locale_2 == map_point) and (roads[_i].locale_1 == selected_locale or roads[_i].locale_2 == selected_locale):
add "gui/misc/path_highlight.png":
xpos roads[_i].locale_1.x + (((roads[_i].locale_2.x - roads[_i].locale_1.x)/_points) * _o)
ypos roads[_i].locale_1.y + (((roads[_i].locale_2.y - roads[_i].locale_1.y)/_points) * _o)
anchor (0.5,0.5)
elif roads[_i].locale_1 == map_point or roads[_i].locale_2 == map_point:
add "gui/misc/path_visible.png":
xpos roads[_i].locale_1.x + (((roads[_i].locale_2.x - roads[_i].locale_1.x)/_points) * _o)
ypos roads[_i].locale_1.y + (((roads[_i].locale_2.y - roads[_i].locale_1.y)/_points) * _o)
anchor (0.5,0.5)
else:
add "gui/misc/path_hidden.png":
xpos roads[_i].locale_1.x + (((roads[_i].locale_2.x - roads[_i].locale_1.x)/_points) * _o)
ypos roads[_i].locale_1.y + (((roads[_i].locale_2.y - roads[_i].locale_1.y)/_points) * _o)
anchor (0.5,0.5)
for _i in range(len(locations)):
# Draw map icons that are not the current position of the player
if locations[_i].discovered:
if map_point != locations[_i]:
# Draw map icons outside movement range
$ _loc = locations[_i]
if not map_point.is_connected(_loc):
add _loc.img + "grey.png" pos (_loc.x,_loc.y) anchor (0.5,0.5)
else:
if selected_locale == _loc:
imagebutton idle _loc.img + "color.png" pos (_loc.x,_loc.y) anchor (0.5,0.5) action [Hide("map"),Show("menubar"),Function(travel,map_point,selected_locale)] focus_mask "gui/button/map_mask.png"
else:
imagebutton idle _loc.img + "white.png" hover _loc.img + "color.png" pos (_loc.x,_loc.y) anchor (0.5,0.5) action [SetVariable("selected_locale",_loc)] focus_mask "gui/button/map_mask.png"
else:
add map_point.img + "color.png" pos (map_point.x,map_point.y) anchor (0.5,0.5)
if selected_locale != None:
for _i in range(len(roads)):
if roads[_i].discovered and (roads[_i].locale_1 == map_point or roads[_i].locale_2 == map_point) and (roads[_i].locale_1 == selected_locale or roads[_i].locale_2 == selected_locale):
$ _mrk_x = (map_point.x + selected_locale.x) / 2
$ _mrk_y = (map_point.y + selected_locale.y) / 2
add "gui/button/map_marker.png" pos (_mrk_x,_mrk_y) anchor (0.5,1.0)
text str(roads[_i].tt_minutes) + " minutes" pos (_mrk_x,_mrk_y - 40) size 14 color "#000" anchor (0.5,1.0)
else:
add "gui/button/map_marker.png" pos (map_point.x,map_point.y) anchor (0.5,1.0)