I'm following Chris Bradfield's tutorial from "Godot Engine Game Development Projects: Build Five Cross-Platform 2D and 3D Games With Godot 3.0" (specifically the tutorial on the 'Escape the Maze' game in chapter 3), and I'm having a problem implementing a proposed turn based movement system for the enemies. The main issue I'm running into is connecting a signal from my player to an enemy that is loaded into the level by a PackedScene variable. The goal is to have the player emit a "moved" signal after each move as shown in the code snippet below (both the player and enemy inherit from Character.gd if that is of any help):
for dir in moves.keys():
The enemy is supposed to listen for the moved signal and then move randomly in the room, as shown in the following code snippet:
if not move(facing) or randi() % 10 > 5:
facing = moves.keys()[randi() % 4]
As is, I cannot figure out how to connect the move signal to the enemy without having an extra instance of the enemy as a child of the level node, which introduces an enemy that isn't being called into the level as the others are. I've tried using other methods, such as:
$Player.connect("moved", self, "_on_Player_moved")
In the enemy code, but that brings up a null instance error. Is there another way to connect these two, or am I going about this the wrong way? Or am I not understanding some aspect of the code? Any feedback would be greatly appreciated.