PacktPublishing / Learning-GDScript-by-Developing-a-Game-with-Godot-4

Learning GDScript by Developing a Game with Godot 4, published by Packt
MIT License
17 stars 8 forks source link

P219 Error in code #7

Open octopuddle opened 3 months ago

octopuddle commented 3 months ago

There are a couple of issues.

Firstly, the code snippet

func _ready(): var player_nodes: Array = get_tree().get_nodes_in_group("player") if not player_nodes.is_empty(): target = player_nodes[0

target isn't declared anywhere, instead on page 218 it is declared as

var player: Player

In the code download it is in the script as

var target: Node2D

Secondly, also in the above snippet, Player is unrecognised, as the player.gd script only contains

extends CharacterBody2D

and not

class_name Player extends CharacterBody2D

The former is in the chapter 9 code download, and the latter appears in the chapter 10 code download.