Really confused about this "Invalid get index"

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By JustMyke

So I need to check against a variable from in another script. Seems quite simple, just use get_node and call the variable where needed right? It’s not working like that this time and I have no idea why.

Spawn Area script:

extends Area2D

var readyCheck

onready var spawnTrigger = get_node("/root/MainScene/SpawnTrigger").trigger

func _on_Area2D_body_entered(body):
    if(spawnTrigger == 1):
	    print("Spawn Enemies"))

Spawn Trigger script:

extends Area2D

var trigger = 0

func _on_Area2D_body_entered(body):
    if body.name == "Player":
	    trigger = 1

So, something like this hasnt been an issue before but for some reason it is now and it’s throwing up “Invalid get index ‘trigger’ (on base: ‘Node2D’)”

:bust_in_silhouette: Reply From: Sviatoslav Vilkovych

I guess, this means that this part of the line

get_node("/root/MainScene/SpawnTrigger")

is returning node without trigger field.

For some reason it was but I fixed it by “parsing” it through another script. It works now, not sure why it didn’t before but it does now

JustMyke | 2020-12-09 08:00