0 votes

Hello.
I have a game where enemies will spawn and come down through certain paths after getting spawned in by a timer. The enemies are their own scene and they have the path code in them, they just need a number from a variable to tell them which path to take.
Well in the code for the enemies, I'm trying to get the variable from the node that will be spawning them in, which would be their parent node after they spawn. The problem is, is that the get_parent().PathToTake isn't getting it and I suspect its because of the fact that while they are in a separate scene there is no parent.
Is there a way to get the new parents variable, or do I need to move the pathing code to the spawner parent and figure out a way to tell each enemy what to do from there?

The node lay out is like this:
Main scene for the game:
MainMainNode
--MobMakerPathChooser (the one who has the children)
----MobTimer

LadyBug Enemy:
Node2D (has the script attached to it)
--Sprite
--Area2D
----Collsision2D

And some Code for the MobMakerPathChooser:

extends Node2D

var rng = RandomNumberGenerator.new()
var PathToTake = 2 #round(rng.randf_range(0, 4))

export (PackedScene) var LadyBug

func onMobTimertimeout():
var mob = LadyBug.instance()
add
child(mob)

Some of the enemies code(with out the pathing ect.):
extends Node2D

const SPEED = 2
const DOWNSPEED = 10

var posx = 0
var posy = 0

var PathToTake = get_parent().PathToTake #<---this is what I think the problem is

func _ready():

if PathToTake == 1:
    self.position.x = 0
    self.position.y = 38
    posx = 200
    posy = 38
if PathToTake == 2:
    self.position.x = 520
    self.position.y = 72
    posx = 440
    posy = 72
if PathToTake == 3:
    self.position.x = 520
    self.position.y = 72
    posx = 328
    posy = 72
if PathToTake == 4:
    self.position.x = -6
    self.position.y = 248
    posx = 74
    posy = 248
in Engine by (14 points)

Please log in or register to answer this question.

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.