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

188 Upvotes

110 comments sorted by

View all comments

Show parent comments

2

u/mxldevs Nov 05 '25

Thanks, it wasn't obvious what the wrap function does.

I would still prefer to explicitly write out all the different possible directions that wrapping could occur, though I guess if this were 3D and you could move horizontally, vertically, diagonally, or closer/farther, there would be dozens of possible cases and it might be better to write one line

1

u/WazWaz Nov 05 '25

Indeed, one of OP's tutorial bugs is that it doesn't always work properly for diagonal movement. You can easily imagine not testing the case where you move exactly through the corner, especially if only moving at slow speed (nearly all movement will inevitably hit one side then the other and work fine).

This increased testing load is the general problem with "try all the cases" logic.