0 votes

I don't know if I have a false understanding of the tool mode, but I have a script which I try to execute in the editor. The script just loads another scene an tries to set a member variable. However, when that script get executed in the editor it throws an error:

Invalid set index 'test' (on base: 'Node2D (AnotherScene.gd)') with value of type 'int'.

here is my script:

extends Node2D

func _ready():
    var anotherScene = load("res://AnotherScene.tscn").instance()
    anotherScene.test = 3

AnotherScene.tscn contains just a node attached to this script:

extends Node2D

var test

Can anyone tell me why this is not working? Is this a bug or my misunderstaning?

in Engine by (188 points)

1 Answer

+1 vote
Best answer

I think you need to add a 'tool' at the beginning of AnotherScene.gd. Try reloading the project otherwise (or just the scene), Godot sometimes needs that to make tool scripts work.

by (345 points)
selected by
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.