Data Persistence - Easy Text File Saving & Reloading

An asset by DeForrestStudios
The page banner background of a mountain and forest
Data Persistence - Easy Text File Saving & Reloading hero image

Quick Information

0 ratings
Data Persistence - Easy Text File Saving & Reloading icon image
DeForrestStudios
Data Persistence - Easy Text File Saving & Reloading

A plugin to assist in saving and loading data using text files.

Supported Engine Version
4.0
Version String
0.0.2
License Version
MIT
Support Level
community
Modified Date
4 days ago
Git URL
Issue URL

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 primitives types are supported.

By default


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

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
    # 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 ui_volume:float = 12.0
var music_volume:float = 12.0

var player_health:int = 50
var player_mana


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()

A plugin to assist in saving and loading data using text files.

Reviews

0 ratings

Your Rating

Headline must be at least 3 characters but not more than 50
Review must be at least 5 characters but not more than 500
Please sign in to add a review

Quick Information

0 ratings
Data Persistence - Easy Text File Saving & Reloading icon image
DeForrestStudios
Data Persistence - Easy Text File Saving & Reloading

A plugin to assist in saving and loading data using text files.

Supported Engine Version
4.0
Version String
0.0.2
License Version
MIT
Support Level
community
Modified Date
4 days ago
Git URL
Issue URL

Open Source

Released under the AGPLv3 license

Plug and Play

Browse assets directly from Godot

Community Driven

Created by developers for developers