0 votes

Lets say I have a GD file like this:

extends Node
var my_dict = {
    name="my_name"
}

I have done a project that opens a GD file, reads some content, and shows me it in a readable way in and LineEdit node, I'll just use print() for the example.

A Button opens a FileDialog then when a GD file is selected, it creates a Fileopening it for READ_WRITE and saving it in a variable named content as File.get_as_text().

func on_button_pressed():
    file_dialog.popup()
    file_dialog.connect("file_selected",self,"on_file_selected",[],CONNECT_ONESHOT)

func on_file_selected(path):
    var file = File.new()
    file.open(path,File.READ_WRITE)
    var content = file.get_as_text()
    read_content(content)

So then, it creates a GDScript named script, sets its source_codeas content and finaly reload().
After that it creates a Node, doing script.new()
Finally I just do print(my_node.my_dict.name) and all work as expected.

func read_content(content):
    var script = GDScript.new()
    script.source_code = content
    script.reload()
    var my_node = script.new()
    print(my_node.my_dict.name)

The next step is the problem, I can't figure out how to modify the original script trying to avoid tedious tricks using all the String's repertoire..
I would be nice to have access to a class/ GD file's methods and members in a simple way like you do with json files, for example.
Is there something I've missed? Or do I have to program a code text editor?

After reading the file, I need to be able to modify it, visualy, in LineEdit nodes, and then save it, it doesn't matter if it overwrites the original or not.

Thanks.

in Engine by (327 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.