Hi i'm Neil and today I have un little big problem...
I develop a game (called Retrail) and for implemented sprite easily i've maked functions factory.
And when the player collide with a trap or an ennemie and die (after the level 6), the game crash.
So... what is the problem
___________________________________________________
Debug :
Error
main.lua:1201: attempt to index local 'pSprite' (a nil value)
Traceback
main.lua:1201: in function 'updateSprite'
main.lua:1312: in function 'update'
[C]: in function 'xpcall'
____________________________________________________
When collision with a trap...
when collision with the ennemie...
And the code...
Bug(s ?) in my code | main.lua:1201: attempt to index local 'pSprite' (a nil value)
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 2
- Joined: Sat Dec 14, 2019 2:34 pm
Re: Bug(s ?) in my code | main.lua:1201: attempt to index local 'pSprite' (a nil value)
You should upload your .love file. Then someone can take a look at the source code to find the bug.
Just a wild guess: You delete sprites by
This creates gaps in the table. So the table has the same length before deletion, but one index is emtpy. If you try to access that index the table returns nil. Use
instead.
Just a wild guess: You delete sprites by
Code: Select all
lstSprites[index] = nil
Code: Select all
table.remove(lstSprites, index)
-
- Prole
- Posts: 2
- Joined: Sat Dec 14, 2019 2:34 pm
Re: Bug(s ?) in my code | main.lua:1201: attempt to index local 'pSprite' (a nil value)
The download link does not work for me. Can't you just upload it as an attachment? Select "Full Editor & Preview" to add attachments to a post.
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Bug(s ?) in my code | main.lua:1201: attempt to index local 'pSprite' (a nil value)
I don't remember the filesize limits for forum attachments but the zip's 35 MB because of the music included
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: Bug(s ?) in my code | main.lua:1201: attempt to index local 'pSprite' (a nil value)
If you call the function playerDeath() in love.update(dt) you initialize a new lstSprites. After creating a new player you jump back into the code line where playerDeath() was called. And there the local loop variable nSprite is still iterating over the old number of #lstSprites. Since there are not enough sprites in lstSprites yet (since lstSprites is still initializing) the next local sprite is nil. And that's where your game crashes.
Do not set lstSprites to an empty list (line 411) and fill it with new sprites while still iterating over it.
Do not set lstSprites to an empty list (line 411) and fill it with new sprites while still iterating over it.
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 2 guests