Page 1 of 1
[FIXED] Yet Again: Fails to index field "?"
Posted: Thu Feb 21, 2013 10:04 pm
by B-Man99
I started a new project yesterday, this one I'm hoping to make into a full-feature game, unlike quick things I've been working on in the past year to get me used to Love2d, etc. I've isolated the loadLevel function, because if I remove the line in love.load() that calls loadLevel(), the game starts without any errors. Most bugs I am able to think about a little (or a lot) and fix, but this particular error is harder for me. Love2d fails to index a nil field, but I cannot seem to figure out what that field is. Can anyone please explain how to fix this error, or give me any advice? Thank you, it would really help!
Re: Yet Again: Fails to index field "?"
Posted: Thu Feb 21, 2013 10:51 pm
by bartbes
Well, thankfully the error gives us a location, main.lua:157, so I look at that and see 3 table index operations that could cause this, namely grid[x], grid[x][y] and leveldata
. So, I added the following code (before 157):
Code: Select all
print(grid[x])
print(grid[x][y])
print(leveldata[i])
That showed me the error was in the second of the two lines, and the result of the print indeed showed grid[x] is nil.
Re: Yet Again: Fails to index field "?"
Posted: Thu Feb 21, 2013 11:21 pm
by B-Man99
bartbes wrote:Well, thankfully the error gives us a location, main.lua:157, so I look at that and see 3 table index operations that could cause this, namely grid[x], grid[x][y] and leveldata
. So, I added the following code (before 157):
Code: Select all
print(grid[x])
print(grid[x][y])
print(leveldata[i])
That showed me the error was in the second of the two lines, and the result of the print indeed showed grid[x] is nil.
Thanks, I would have done that except that my console opens up but doesn't print anything. I saw a similar problem on these forums but with no solution. Thank you for helping. Now I just need to figure out why grid[x] is nil. I'll update this post if I figure out why, but I could still use advice until then. Thanks, bartbes (I'd give you karma, but now there's no karma)
Re: Yet Again: Fails to index field "?"
Posted: Thu Feb 21, 2013 11:25 pm
by B-Man99
Update: bla bla bla
Edit: FIXED. THANK YOU FOR YOUR HELP