Godot Version
4.2.2
Question
Hi! I want to support a datapack-like system where users can add content to the game. I created this example where files in the strings folder will be parsed for text and then labels will be created. However, I have no idea how to export it in such a way that retains this functionality. Currently, I’m only able to export an .exe which simply contains the last labels before I exported it.
Root node “Game”
extends Node2D
func _ready():
const PATH_TO_JSON = "res://strings/"
var dir = DirAccess.open(PATH_TO_JSON)
var strings = []
if dir:
var json_files = dir.get_files()
for file in json_files:
if file.ends_with(".json"):
var contents = FileAccess.open(PATH_TO_JSON + file, FileAccess.READ)
var json = JSON.new()
var json_string = contents.get_as_text()
var error = json.parse(json_string)
if error == OK:
var data_received = json.data
strings.push_back(data_received.text)
else:
print("JSON Parse Error: ", json.get_error_message(), " in ", json_string, " at line ", json.get_error_line())
else:
print("Error: Could not open " + PATH_TO_JSON)
create_labels(strings)
func create_labels(labels):
var vertical_spacing = 20
var start_position = Vector2(10, 10)
for i in range(len(labels)):
var label = Label.new()
label.text = labels[i]
label.position = start_position + Vector2(0, i * vertical_spacing)
add_child(label)
