Page 1 of 1

Need Help with a Simplegametutorials Snake Game

Posted: Sun May 05, 2024 12:49 pm
by Gigagear
Hello! I've been trying to make a snake game based on this tutorial --> https://simplegametutorials.github.io/love/snake/

Everything works fine except the snake will not die.
I've tried comparing and rewriting the code to match more closely with how the tutorial is formatted but nothing changed.

If someone could tell me where I did wrong, that would be great

Re: Need Help with a Simplegametutorials Snake Game

Posted: Sun May 05, 2024 2:40 pm
by keharriso
Hello!

The problem looks like a typo. You are using "nextXpos" and "nextYpos" instead of "newXpos" and "newYpos".

You need to replace this:

Code: Select all

for segmentIndex, segment in ipairs(snakeSegments) do
	if segmentIndex ~= #snakeSegments
		and nextXPos == segment.x
		and nextYpos == segment.y then
		canMove = false
	end
end
With this:

Code: Select all

for segmentIndex, segment in ipairs(snakeSegments) do
	if segmentIndex ~= #snakeSegments
		and newXpos == segment.x
		and newYpos == segment.y then
		canMove = false
	end
end

Re: Need Help with a Simplegametutorials Snake Game

Posted: Sun May 05, 2024 8:20 pm
by Gigagear
I'll try that. Thanks for responding!

EDIT: Ok so, update. I replaced those lines but nothing changed. I appreciate you correcting me on this though.

EDIT 2: I messed up the if nesting like a goober. Thanks for helping!