Godot Version 4.3
I have a dialogue scene saved with a script attached to it’s root with @export var dalogue_json : JSON in it.
this is easy to work with in the godot editor. I put that scene in and I can just drag a json file onto the node and done.
Now I want to start creating such dialogue scenes from another gdscript though.
Something like this:
extends Node
@onready var dialogue_scn = preload("res://scenes/dialogue/dialogue.tscn")
func start_dialogue(path_to_json: String):
var dialogue_obj: DialogueBox = dialogue_box_scn.instantiate()
dialogue_obj.dialogue_json = get_json(path_to_json)
add_child(dialogue_box_obj)
func get_json(path_to_json: String) -> JSON:
**Please help me create this function**
I cannot seem to get from a filepath to a JSON object. Wherever I look, people always seem to want to get to a Dictionary, or just a string.
I can go from a filepath to a String with the contents of that file using FileAcess, but then how to go from String to JSON? Any help is much appreciated!