The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

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')"

in Engine by (22 points)

1 Answer

0 votes

I guess, this means that this part of the line

get_node("/root/MainScene/SpawnTrigger")

is returning node without trigger field.

by (19 points)

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

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.