Created
October 31, 2022 10:56
-
-
Save bruchmann/614bfb38092205f03456ce82baef818c to your computer and use it in GitHub Desktop.
GDScript Save-Game Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends CharacterBody2D | |
class_name Player | |
# […] | |
func compute_save_state() -> Dictionary: | |
var save_state: Dictionary = {}; | |
save_state["equipped_gun"] = self.equipped_gun; | |
save_state["inventory"] = self.inventory; | |
return {"key": "player", "value": save_state} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Node | |
class_name SaveGame | |
func compute_save_state() -> Dictionary: | |
var persistable_nodes: Array = get_tree().get_nodes_in_group("persistable"); | |
var save_state: Dictionary = {}; | |
for node in persistable_nodes: | |
if not node.has_method("compute_save_state"): | |
continue; | |
var state_to_save: Dictionary = node.compute_save_state(); | |
save_state[save_to_state.key] = save_to_state.value; | |
save_game_state(save_state); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment