Get Size of Array

Why does this code return 0? How do I get it to return 1?

[code]
local spawnObjects = {OBJECT1 = {image = “images/yellowRect.png”, color = “YELLOW”}};

numSpawnObjects = table.getn(spawnObjects);
print(numSpawnObjects);
[/code] [import]uid: 39238 topic_id: 7053 reply_id: 307053[/import]

It has to do with how Lua counts keys in it’s tables.

There’s a question on StackOverflow about this very thing.
http://stackoverflow.com/questions/652957/how-do-i-get-the-number-of-keys-in-a-hash-table-in-lua

By using spawnObjects as a dictionary (rather than a list) you’re getting the weird count.

Try this:

[code]
local spawnObjects = {
{image = “images/yellowRect.png”, color = “YELLOW”},
}

– shorthand
print(#spawnObjects)
[/code] [import]uid: 9048 topic_id: 7053 reply_id: 24722[/import]