Godot Data Persistence - Easy Test File Saving & Reloading
A downloadable Godot-Data-Persistence
Godot-Text-File-Data-Persistence
All DataDict objects are stored as plain text files. They are essentially CSV files, but the default delimiter is `~`. You can change the delimiter if you'd like, but if you do so afterward saving and DataDicts, you will have to convert those files.
All DataDicts are placed in the "user://Data" directory. During launch, any DataDicts within that directory are automatically loaded on startup.
Currently only int, float, String, Vector2, and Vector2i are supported data types to reload. I hope to support the rest of the data types soon.
Data Methods
`func new_data_dict(dict_name:String) -> Variant`
Creates a new DataDict with the specified name.
`func save_all() -> Variant`
Saves all existing DataDicts at once.
DataDict Methods`add(field_name:String, field_value:Variant) -> Variant`
`add(fields:Dictionary) -> Variant`
Add a new field, or fields if given a Dictionary, to the data dict. If the field already exists, it will do nothing, and return void. If you add a non-primitive type, an error will pop, and the field will not be added.
`remove(field_name:String) -> Variant`
`remove(field_names:Array) -> Variant`
Removes a field, or fields if given an Array. If the field does not exist, it will present a error message.
`update(field_name:String, field_value:Variant) -> Variant`
`update(fields:Dictionary) -> Variant`
Update the value or values fi given a dictonary, of an existing field.
`save() -> void`
Saves the data dict to a text file.
Basic Example of Creating DataDict, and Adding Fields
extends Node2D var ui_volume:float = 12.0 var music_volume:float = 12.0 var player_health:int = 50 var player_mana:int = 50 func _ready() -> void: Data.new_data_dict("player_data") Data.data["player_data"].add("health", player_health) Data.data["player_data"].add("mana", player_health) player_health -= 20 player_mana -= 10 # You can update a single field Data.data["player_data"].update("health", player_health) # Or you can update multiple fields Data.data["player_data"].update({"health": player_health, "mana": player_mana }) Data.data["player_data"].add("position", position) # Write DataDict to disk in plain text file Data.data["player_data"].save() Data.new_data_dict("settings") Data.data["settings"].add({"ui_volume":ui_volume, "music_volume:":music_volume, }) Data.data["settings"].save()
Example of Loading in Data from Existing Fields
extends Node2D var player_health:int = 50 func create_data_dicts(): Data.new_data_dict("player_data") Data.data["player_data"].add({"health": player_health, "position": position }) Data.data["player_data"].save() func load_data(): position = Data.data["player_data"].fields["position"].value player_health = Data.data["player_data"].fields["health"].value func _ready() -> void: load_data() create_data_dicts()
Godot's Guide to Installing Plugins:
https://docs.godotengine.org/en/stable/tutorials/plugins/editor/installing_plugi...
GitHub / Source:
https://github.com/Robert-DeForrest-Reynolds/Godot-Text-File-Data-Persistence
If you have any question, feel free to leave a comment, or come onto the discord:
Status | Released |
Category | Assets |
Author | DeForrest Studios |
Tags | data-persistence, Godot, godot-4, loading, load-text-files, save-text-files, saving, tool, utility |
Average session | A few seconds |
Languages | English |
Download
Click download now to get access to the following files:
Leave a comment
Log in with itch.io to leave a comment.