I have created a class that is intended to handle the various characters in the game, with each character being created as an instance of that class.
Here's an extremely slimmed down version of the game containing a simplified version of the code in question:
Code: Select all
define elaine = Actor("elaine")
define e = Character("[elaine.display_name]", who_prefix="{color=[elaine.color]}", who_suffix="{/color}")
define mary = Actor("mary")
define m = Character("[mary.display_name]", who_prefix="{color=[mary.color]}", who_suffix="{/color}")
init -1 python:
ActorList = []
import renpy.store as store
class Actor(store.object):
def __init__(self, characterName):
#Mechanics
self.initialized = False
self.enabled = True
self.location = "UNINITIALIZED_LOCATION"
self.last_location = "UNINITIALIZED_LAST_LOCATION"
self.room = "UNINITIALIZED_ROOM"
self.is_home = True
self.is_asleep = False
self.home_name_location = "UNINITIALIZED_HOME_NAME"
self.has_shower = False
self.inventory = []
#Identity
self.name = characterName
self.display_name = "UNINITIALIZED_PERSONAL_NAME"
self.thing_name = "UNINITIALIZED_THING_NAME"
self.has_name = False
self.color = "#89CFF0"
ActorList.append(self)
label instantiate_characters:
python:
for item in ActorList:
if not item.initialized:
renpy.call("instantiate_" + item.name)
return
label instantiate_elaine:
if not elaine.initialized:
#Mechanics
$ elaine.initialized = True
$ elaine.enabled = True
$ elaine.location = "Elaine's Home"
$ elaine.last_location = "Elaine's Home"
$ elaine.room = "Elaine's Living Room"
$ elaine.is_home = True
$ elaine.is_asleep = False
$ elaine.home_name_location = "Elaine's Home"
$ elaine.has_shower = True
$ elaine.inventory = []
#Identity
# $ elaine.name = characterName ### Set upon actor creation.
$ elaine.display_name = "Nurse"
$ elaine.thing_name = "deer girl"
$ elaine.has_name = False
$ elaine.color = "#ff8ca3"
jump instantiate_characters
label instantiate_mary:
if not mary.initialized:
#Mechanics
$ mary.initialized = True
$ mary.enabled = True
$ mary.location = "Mary's Home"
$ mary.last_location = "Mary's Home"
$ mary.room = "Mary's Garden"
$ mary.is_home = True
$ mary.is_asleep = False
$ mary.home_name_location = "Mary's Home"
$ mary.has_shower = False
$ mary.inventory = []
#Identity
# $ mary.name = characterName ### Set upon actor creation.
$ mary.display_name = "Mary"
$ mary.thing_name = "sheep girl"
$ mary.has_name = True
$ mary.color = "#8cc2ff"
jump instantiate_characters
# The game starts here.
label start:
call instantiate_characters
scene bg room
show eileen happy
e "Why hello there!"
m "Hi! Could you give us some directions? We're lost."
e "Where are you heading?"
m "The library!"
e "Oh, just continue down this street and then take the third left."
m "Thank you, kindly! What was your name, again?"
if not elaine.has_name:
$ elaine.display_name = "Elaine"
$ elaine.has_name = True
e "*giggles* The name's [elaine.display_name]! Pleasure to meet you!"
m "Pleased to meet you, [elaine.display_name]! I'm [mary.display_name]!"
e "Pleased to meet you too, [mary.display_name]!"
m "We gotta get going now! Bye!"
e "Bye!"
# This ends the game.
return
Firstly, any changed instance variables remain changed on rollback or when loading without having exited the game. For example, in this simplified code, if you save before Elaine gives you her name, then load that save after she's given it, her dialogue tag will say "Elaine" instead of "Nurse".
Secondly, if you exit the game, start it back up, and load a save, all instance variables will have reverted back to the class defaults. So for example, Elaine's dialogue tag will say "UNINITIALIZED_PERSONAL_NAME" instead of "Nurse" or "Elaine".
Does anyone know how to solve these issues? Any help would be greatly appreciated! <3