nil value - The Bane of my &$@^! Existence

It seems like I take 1 step forward and three steps back every night that I try to make some progress with my programming with Codea. I get errors when I try a touch sample, or call a function,and sometimes I even get errors when I just try and call a global variable. And all of the errors have the same little text in paranthesis, (nil value). Tell me I am trying to assign a string to an integer variable, or that I am trying to stick a round peg in a square hole, anything but that &^$%^! NIL VALUE.

I know for help I need to include some samples, but at this point I am just venting my spleen. It is frustrating as can be to have a program stuck in my head and not be able to get it out. And it is a simple text game that I could write in VB in a day or two, I am not trying to create a new gaming engine for a next gen platform. It is not ambitous at all, but it seems simple things such program flow and tables are something way above my knowledge level.

Anyhow, NIL?!? Why oh why does this plague me? See there is a question in there. :slight_smile:

Thanks…
Munkie

Well, if you feel like posting some code, I’d
be happy to peruse it and see if I can help you figure it out :slight_smile:

@Munkie, nil usually bites when you try to use a variable that hasn’t been assigned. It’s fine to say x = 10 without ever mentioning x before, but if you jump straight to y = x + 1 without defining x, you get bopped.

@Munkie, I usually get that type of error when trying to get a key from a table and the key is not on the table. Anyway, sprinkle your code with assert(such and such != nil, “such and such was nil”) and might help you catch the errors at the source.

Yeah, it happens to me with capitalization in names, (i.e. I type boxwidth when it is supposed to be boxWidth) .

I think the thing that is killing me is that in Lua you don’t have to declare variables before using them, so mistyping a variable name doesn’t give you a compiler error, it just causes your code to malfunction in weird ways and give cryptic errors. I start to see the value of languages that require declaring stuff before using it.