File Access
Read from File
Create a script that will be Autoloaded called data_characters.gd:
extends Node
const DATA_CHARACTERS = "res://data/character/db_characters.json"
var _data : Dictionary
func _ready():
self._load_characters_data()
ffunc _load_characters_data():
var _file := FileAccess.open(DATA_CHARACTERS, FileAccess.READ)
var _json_object := JSON.new()
var parse_error := _json_object.parse(_file.get_as_text())
if parse_error != OK:
printerr("JSON File: '", DATA_CHARACTERS, "' could not be parsed.")
return
_file = null # Close File
self._data = _json_object.get_data()Last updated