0 votes

I'm making a little to plugin for Escoria to get used to gdscript. Is a bunch of simple dialogs to get user data and generate the full tree assigning the data so I don't need to put the info in different nodes, or forgot anything, and make the life a little easier.

It works ok, but I can't find how to assign external scripts to the tree. If I do it with the editor, the .tscn file starts with:

[gd_scene load_steps=4 format=1]

[ext_resource path="res://globals/player.gd" type="Script" id=1]
[ext_resource path="res://scenes/testplayer_anims.gd" type="Script" id=2]

[sub_resource type="SpriteFrames" id=1]

But my code generate a .tscn that starts with:

[gd_scene load_steps=3 format=1]

[ext_resource path="res://globals/player.gd" type="Script" id=1]

[sub_resource type="SpriteFrames" id=1]


func _on_ConfirmationDialog_confirmed():
    var dir = Directory.new()
    var scene_name = get_node("vbox/hbox1/filePath_txt").get_text()
    var telekinetic = get_node("vbox/hbox2/Telekinetic_checkbox").is_pressed()
    var anims_script = scene_name.get_base_dir() + "/"+  scene_name.get_file().basename() + "_anims.gd"
    var player

    dir.copy("res://addons/Easycoria/templates/player_anims_empty.gd", anims_script)
    player = preload("res://addons/Easycoria/templates/player.tscn").instance()
    # TODO Add anims script as external resource

    var packed_scene = PackedScene.new()
    ResourceSaver.save(scene_name, packed_scene)

I suppose that the main problem is that I created the setanimations and settelekinetic functions in the original player.gd script from escoria and It doesn't add the script, only assign it. But I can't find the code to add it.


in Engine by (18 points)
edited by

1 Answer

0 votes
Best answer

I think I didn't understand your code fully but my guess is that you need to add the scene to the tree (root).

I. e. look here:


And you probably need to make it the current scene if you want to see it.

get_tree().set_current_scene( player )
by (3,358 points)
selected by

This is the main problem. I don't want to work in the current scene.

I'm opening a template scene, changing values exported in its script and saving the scene with a different name. Then I can add it to different rooms as a scene child.

But the new scene isn't ended if I can't add the second external .gd script.

I can add more info if you need it.

To just save a scene it won't have to be added to the tree or set as current IMHO.

If I see it correctly, your sample code doesn't show which methods you actually call to assign the script. That is probably hidden in the method "set_animations". So I can't tell what that code is doing wrong.

It only makes sense to set one script per node.

Naturally, you can have multiple nodes in a scene and each can have an own script.
And that is probably inside set_animations.

If that is all performed correctly but not saved correctly then it might be some kind of timing/signal propagation problem. But I'm going to far ahead. First, we got to see where and how the set_script is actually done. Second, you need to check if godot puts out any warnings/error on stdout at that time.


You are right, I was assigning the script wrong in set_animations.

My original code was:

func set_animations(anims_script):
    animations = anims_script

And it must be:

func set_animations(anims_script):
    animations = load(anims_script)

I know that it only makes senses to set one script per node, but Escoria works this way. It had a globals/genericelement.gd (player.gd, item.gd), that the designer doesn't need to edit, to manage the logic and a second xxxanims.gd where the designer edits some arrays to asign the animations.

I suppose that it must be to keep the roles separated (designer, coder, gfx artist) so they work in different files.

Thanks for your time

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.