Trying to add a location to add_child

Godot Version

4.3

Question

im trying to figure out add child and I was following a tutorial where he used

extends Node2D

var Laser = preload("res://Scenes/Laser.tscn")
   
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
   spawn(Vector2(0,0))
func spawn():
   var instance = Laser.instantiate()
   instance.position = pos
   add_child(instance)

I changed the function name to spawn otherwise its the same what do I replace pos with since i tried putting a vector 2 there and stuff but it isnt working what do I have to put there?

be more specific. does it throw an error or just nothing happens?

what did you change?

your function needs an argument. you either skipped doing it or deleted it at some point.

func spawn(pos):
   var instance = Laser.instantiate()
   instance.position = pos
   add_child(instance)

also, any tutorial that doesn’t use static typing is a bad tutorial. I recommend the godot official docs, as that explains everything very well and broken up into small, easy to understand parts.

this is what the code should look like with static typing. you need it to catch possible bugs and understand it better. it also improves performance. for instance, pos should be a Vector2, and then only accept a Vector2, and with static typing, the editor will tell you more clearly what is wrong.
other things I changed: function returns void, meaning it doesn’t return anything.

func spawn(pos : Vector2) -> void:
   var instance : Node2D = Laser.instantiate()
   instance.position = pos
   add_child(instance)

also, you are on 4.3 so position has to be changed AFTER add_child:

func spawn(pos : Vector2) -> void:
   var instance : Node2D = Laser.instantiate()
   add_child(instance)
   instance.position = pos

and this from tutorial

dont mind the second inst

read my comment.

as you can see there, inst has an argument pos, just as I said.

man that was a waste of time xd for both of us