I've been working on procedural map generation in TIC-80 (ambitious I know...) And I've hit a problem that's got me stumped.
I need to write a function that builds a table of attributes for an object, that I can call later...
Something like:
Function build_obj()
Local z={
attribute1=blah,
attribute2=blah,
attribute3=spam}
return z
end
From there I can create objects like so:
obj1=build_obj()
obj2=build_obj()
etc...
The problem is when I try referring to my objects:
If obj1.attribute==blah then
do awesome stuffs
end
I always get an error saying
"Attempting to index a nil value"
I understand what this means... Somewhere in the deep recesses of my code, my table of attributes is getting lost. And so obj1 is being assigned no value.
I've been googling this problem... It could happen if I typed
obj1=build_obj
By leaving off the parentheses I'm assigning the entire function to the variable object. I've double checked and this isn't my problem.
Anyone know what I'm doing wrong??