Help finishing my game from tutorial

Have you double checked (with prints) that the init() functions in both collections are running?

Another thing to check is the id that you set on the collections. It must be unique and is the name that you should use in the messages.

Lua only has the table type to use for data structures. It is an associative structure with key-value pairs, just like dictionaries/hash tables in many other languages.

Lua has a few special constructs to allow you to use tables as arrays:

local t = { my_key = 123, my_key2 = 456 }          -- ordinary key-value
local a = { "abe", "charlie", "dorothy", "lion" }  -- "array" style

the table a is an ordinary key-value table, but its keys are automatically set to integer values starting with 1. It is equivalent to:

local a = { [1] = "abe", [2] = "charlie", [3] = "dorothy", [4] = "lion" }

With the array style table, you can use the # operator that counts the elements, starting at integer key 1 and going on until it finds no subsequent integer key. That is why you can’t use the # operator on any key-value table to count the elements. Indexes must be without breaks:

local b = { 12, 23, 34 }
print(#b) --> 3
b[100] = 45
print(#b) --> 3

There are also two functions to iterate over tables. One is pairs() that iterates over all key-value pairs in an arbitrary table. The other is ipairs() (index-value-pairs) that iterates over an integer-indexed table. The table module also includes some handy functions to manipulate tables.

1 Like

it is starting to make a little sense, sorry for bugging you so much. one of these days i’ll catch up to your level o knowledge for now i’m just a lowly programming scrub!