Good morning all.
Im having some issues getting my head around save games. ive read a bit of documentation but the penny hasnt dropped yet.
I understand that in order to keep save files small and save time short, the game only saves variables whose value have changed since the game loaded.
I also understand that the default command was added to allow coders to tell renpy "if no other value is assigned to this variable, use this value"
I am having some issues getting my head around implementation though. In my mind, all of my variables are important, it's why i declared them in the first place, so when I load a game and S**t is going mental because half of the values the game needs are no longer defined it sorta throws me off.
I declare all of my variables and their starting values in one function which Is the first thing called in the start()
The function defines a few classes and then declares all the variables with their default values of which there are currently only about 40 but i need the values of all of these variables to be saved so that when the game loads, it is in exactly the same state as it was when it was saved otherwise there isn't much point saving.
Anyone with a good handle on this able to break it down a bit and maybe help explain what I need to do?
Much obliged
Save games
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
- Empish
- Veteran
- Posts: 221
- Joined: Thu Jan 14, 2016 9:52 pm
- Projects: Efemural Hearts, It Ends With Graduation
- itch: empish
- Contact:
Re: Save games
If you're declaring a variable in a function I believe that due to scoping it will only exist in that function.
Try declaring your variables themselves at the top level of a file, that way they can all be found at the appropriate time.
Try declaring your variables themselves at the top level of a file, that way they can all be found at the appropriate time.
- Remix
- Eileen-Class Veteran
- Posts: 1628
- Joined: Tue May 30, 2017 6:10 am
- Completed: None... yet (as I'm still looking for an artist)
- Projects: An un-named anime based trainer game
- Contact:
Re: Save games
You could map the variable to a collection (python datatype) and just default that...
default var_map = {} # this gets saved / loaded
function something(): global var_map ... var_map[ 'pc_health' ] = var_map.get( 'pc_health', 50 ) # default 50, else saved value
# just remember to only init a value if it doesn't exist, like above
default var_map = {} # this gets saved / loaded
function something(): global var_map ... var_map[ 'pc_health' ] = var_map.get( 'pc_health', 50 ) # default 50, else saved value
# just remember to only init a value if it doesn't exist, like above
Frameworks & Scriptlets:
- Speech Bubble dialogue system
- Multiple Notify with ATL and history
- (WIP) Radial Masking - needs updating to use Shader
- 7.4 - Smooth Tinting using ATL and matrixcolor
- Several other repositories there too
Re: Save games
Ive done some more digging and i realise that I am still using older terminology. The variables are defined inside a call function i.e
as an example
what is happening is that when the player tries to load their saved game some of the variables are "not defined"
Code: Select all
start:
call declarations
return
label declarations:
python:
class NPC(object):
def __init__(self, name, affection, lust, corruption, location, ispresent, job, cash, intro, status, home):
self.name = name
self.affection = affection
self.lust = lust
self.corruption = corruption
self.location = location
self.ispresent = ispresent
self.job = job
self.cash = cash
self.intro = intro
self.status = status
self.home = home
$ weekday = 0
$ totaldays = 0
$ day_values = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
$ day_time = 16
return
as an example
what is happening is that when the player tries to load their saved game some of the variables are "not defined"
- Remix
- Eileen-Class Veteran
- Posts: 1628
- Joined: Tue May 30, 2017 6:10 am
- Completed: None... yet (as I'm still looking for an artist)
- Projects: An un-named anime based trainer game
- Contact:
Re: Save games
default var = value
# outside any label or control flow block
is the advised way to set defaults that are saved (Ren'py basically uses the default if the value does not already exist on any load)
You could either rework the code to use that (like suggested above) or directly import the store and address that within __setattr__ and __getattr__ for your object.
Also: Personally I'd put the class within an "init python:" block rather than the start:->call label->declare route, it will still be available for instances just the same.
# outside any label or control flow block
is the advised way to set defaults that are saved (Ren'py basically uses the default if the value does not already exist on any load)
You could either rework the code to use that (like suggested above) or directly import the store and address that within __setattr__ and __getattr__ for your object.
Also: Personally I'd put the class within an "init python:" block rather than the start:->call label->declare route, it will still be available for instances just the same.
Frameworks & Scriptlets:
- Speech Bubble dialogue system
- Multiple Notify with ATL and history
- (WIP) Radial Masking - needs updating to use Shader
- 7.4 - Smooth Tinting using ATL and matrixcolor
- Several other repositories there too
Re: Save games
awesome thanks for the tip. Ive moved the class definitions into the init python block and it seems to have resolved my issue. As always I am really grateful for the help!
Who is online
Users browsing this forum: Majestic-12 [Bot]