I can’t count the number of times that I get ready to ask the forums a question about a problem I’m having and I solve it while typing the forum post.
Usually these are problems that are simple n00bie issues and you just don’t see them looking at the code. As I type in the question I usually spot my mistake and voila! The forums debugged my code for me.
Now since I’m a professional educator by trade, we should of course make this educational, so I will share my problem which I’m guessing happens to many people.
I had this block of code:
lines[#lines+1] = {}
lines[#lines+1].x = event.x
lines[#lines+1].y = event.y
I was getting the error:
game.lua:292: attempt to index field ‘?’ (a nil value)
I did a print right before it and every variable was NOT nil… #lines+1 was 29.
Well the problem is when this line executed:
lines[#lines+1] = {}
#lines+1 was now 30 and entry 30 in the table is nil.
So I changed the code to read:
local l = #lines+1
lines[l] = {}
lines[i].x = event.x
lines[i].y = event.y
It’s a very rookie mistake that bytes even us 30 year programming vets.
[import]uid: 19626 topic_id: 25047 reply_id: 325047[/import]