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?

asked Feb 26, 2019 in Engine by TobiLa (168 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.

answered Feb 27, 2019 by TheFamousRat (305 points)
selected Feb 27, 2019 by TobiLa
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.