following the "getting started, your first 2d game" tutorial, what am i doing wrong???

Godot Version

4.4.1 Windows 64

Question

After the part in “coding the player” where I add “position += velocity * delta” & “position = position.clamp(Vector2.ZERO, screen_size)”, when I try to playtest it gives me an error that says “invalid type in function ‘clamp’ in base ‘Vector2’. Cannot convert argument 2 from Nil to Vector2’.” My code looks exactly the same as the tutorial so I’m not sure why it’s not working, and I’ve never coded in this language before so I’m not familiar enough to tell what exactly the error is even implying. If someone could explain it like I’m stupid or just tell me straight up what to do I would greatly appreciate it.


This error means that you declared the variable screen_size but never assigned a value to it.

Did you include that _ready() function from Coding the player — Godot Engine (stable) documentation in English?

func _ready():
	screen_size = get_viewport_rect().size

You posted incomplete code. In the textbook, at the end of the lesson, the full correct code is always given. Compare it to what you wrote.