I HAVE AN ERROR

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By WALLUBHAI

E 0:00:01.729 get_node: Node not found: StartPosition.
<C++ Error> Condition “!node” is true. Returned: __null
<C++ Source> scene/main/node.cpp:1381 @ get_node()
Main.gd:13 @ new_game()
Main.gd:10 @ _ready()

This Is The Error

    extends Node

var Circle = preload("res://objects/Circle.tscn")
var Jumper = preload("res://objects/Jumper.tscn")

var player

func _ready():
	randomize()
	new_game()
	
func new_game():
	$Camera2D.position = $StartPosition.position
	player = Jumper.instance()
	player.position = $StartPosition.position
	add_child(player)
	player.connect("captured", self, "_on_Jumper_captured")
	spawn_circle($StartPosition.position)
	
func spawn_circle(_position=null):
	var c = Circle.instance()
	if !_position:
		var x = rand_range(-150, 150)
		var y = rand_range(-500, -400)
		_position = player.target.position + Vector2(x, y)
	add_child(c)
	c.init(_position)
	
func _on_Jumper_captured(object):
	$Camera2D.position = object.position
	object.capture()
	call_deferred("spawn_circle")

This Is The Code PLSS HELP!!

:bust_in_silhouette: Reply From: kidscancode

It looks like line 13 is this one:

$Camera2D.position = $StartPosition.position

It seems that one of those nodes doesn’t exist. Check the name/spelling of your nodes.

:bust_in_silhouette: Reply From: Czselu349

I think all you gotta do is to swap these 2 lines of code:

player.position = $StartPosition.position
add_child(player)

The error occured, because you were trying to set a property of a nide that hasn’t been instanced yet. You just stored it in a varaiable. Sequence matters :wink: