0 votes

Hi.

My task is:
Open simple txt files in script editor from gdscript code safely.

I know, script editor can open txt files from editor's user interface, but how I can do this trick from code? I find some solution, but what way isn't stable for Engine.

So, my code here:

tool
extends Node2D

export (String, FILE, "*.txt")  var cutscene_file = "" setget open_file

export (bool)  var to_edit = false setget back_to_write

func open_file(new_path):
    if (cutscene_file != new_path):
        cutscene_file = new_path

func back_to_write(go):
    if Engine.editor_hint && go:
        var file = load(cutscene_file)
        if (file != null):
            EditorPlugin.new().get_editor_interface().edit_resource(file)
            # ^ This row make these problems
        file = null

If code runs successfully, I see this errors in output:

core/object.cpp:2012 - Object [Object:34316] was freed or unreferenced while a signal is being emitted from it. Try connecting to the signal using 'CONNECT_DEFERRED' flag, or use queue_free() to free the object (if this object is a Node) to avoid this error and potential crashes.

core/object.cpp:2012 - Object [Object:34315] was freed or unreferenced while a signal is being emitted from it. Try connecting to the signal using 'CONNECT_DEFERRED' flag, or use queue_free() to free the object (if this object is a Node) to avoid this error and potential crashes.

In other rare cases, Engine crashes.

How can I get an editor interface in code? I didn't find anything in code reference, what not includes "EnginePartThing.GetOtherThingThatYouNeed" to do.

in Engine by (22 points)

1 Answer

0 votes
Best answer

This plugin can edit text files in Godot, so maybe you can check out the code there?

by (7,190 points)
selected by

Wow!) Really nice thing!)

I made some simple plugin myself at what moment, maybe I try modify code from link for my own purposes)

Thanks!)

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 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 webmaster@godotengine.org with your username.