0 votes

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:
--MobMakerPathChooser (the one who has the children)

LadyBug Enemy:
Node2D (has the script attached to it)

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()

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
asked Nov 10, 2019 in Engine by DoctorPumpkins (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 How to use this Q&A? before posting your first questions.