Need Help with a Simplegametutorials Snake Game

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Gigagear
Prole
Posts: 2
Joined: Fri May 03, 2024 11:53 pm

Need Help with a Simplegametutorials Snake Game

Post 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
Attachments
main.lua
the main.lua from the site
(4.63 KiB) Downloaded 80 times
main.lua
my main.lua
(3.65 KiB) Downloaded 47 times
examplefromsite_snake.love
From the website
(1.2 KiB) Downloaded 67 times
SnakeStillAlive.love
this one is mine
(388.6 KiB) Downloaded 58 times
User avatar
keharriso
Citizen
Posts: 99
Joined: Fri Nov 16, 2012 9:34 pm

Re: Need Help with a Simplegametutorials Snake Game

Post 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
LÖVE-Nuklear - a lightweight immediate mode GUI for LÖVE games
Gigagear
Prole
Posts: 2
Joined: Fri May 03, 2024 11:53 pm

Re: Need Help with a Simplegametutorials Snake Game

Post 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!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 2 guests