Godot Version
4.2.1
Question
Here are some general questions about how I’m structuring my data for in-game consumption and saving/loading states.
I have a bunch of locations in game, say they’re “houses with rooms”. So I have files like house01.gd
defined as resource and implementing a dictionary of rooms, in such a way:
extends Resource
const rooms = {
'kitchen':
{
'name': 'Kitchen',
'floor': 0,
'visible': true,
'visible_at_start': true
},
'bedroom':
{
'name': 'Bedroom',
'floor': 1,
'visible': false,
'visible_at_start': false
},
...
These are kinda like “config files” or maps for the game.
At the beginning of the game or whenever a player is accessing a given house, I’d do:
var current_location = preload('res://data/house01.gd')
# run some logic
# then...
func draw_rooms(current_location) -> void:
perform_some_displaying(current_location)
So far it all fits my needs and works, now I’m wanting to save the current game state and load it back.
What I’m NOT currently doing yet is storing the game data anywhere, so I SUPPOSE my first step is to do something like:
func draw_rooms(current_location) -> void:
perform_some_displaying(current_location)
# when player enters a room, set it as visible, then:
var game_state = load('res://data/GameState.tres')
game_state.add_location_data(current_location.rooms[current_room].visible)
Where GameState is another Resource
that would store all the current, ever changing, state of the game.
(Please ignore I’m loading GameState at that point, in reality it happens at script preload time, it’s just here for the sake of readability)
My assumption is that whenever I needed to save or load the game I could just use:
ResourceSaver.save(game_state, save_path)
Now to the questions:
-
is all the above making sense, design-wise, or are there better approaches to this?
-
does
house01.gd
even need to be aResource
? These are pretty much read-only config files that contain some sort of “map of the game”, I don’t recall why I thought they would need to be resources, but now I’m questioning that -
if I access and change the state of the game via
var game_state = load('res://data/GameState.tres')
can I just run the same logic from separate scripts and they would all update the same object or do I need to somehow “share”game_state
between them?
Thanks!