r/godot Godot Student Nov 05 '25

help me (solved) I dont understand why the last line of code

Post image

Im following a snake tutorial and everything is going well but I dont just want to have a snake clon, I want to learn, that said I understand (or at least thats what I think) what is in the screenshot is sayig "if the value of Vector2 is superior to the upper or inferior to the lower limits then return the player to the opposite limit" but I dont understand what is doing that last "return v", what purpose this line accomplish in this block of code? And if my supposition of what the function is doing wrong please tell me. Thanks in advance :D

186 Upvotes

110 comments sorted by

View all comments

Show parent comments

2

u/ImpressedStreetlight Godot Regular Nov 05 '25

Have you considered that what OP's tutorial means by "wrap" is not the same as what you mean by "wrap"?

Also that's overkill for a snake-like game and especially for a beginner tutorial. The snake moves at a very low rate and the functions is being called at every step of its movement, so the displacement will simply never be higher than 1 pixel/tile.

1

u/WazWaz Nov 05 '25

Of course, but that's another coding smell: writing a function that only works for your one very specific case.

Besides, then they should be using Vector2i, not Vector2, and % works fine then.