Skip to main content
GameDev.net gamedev.net
🔒 Locked

Lua Tables

Started by Paul7 Apr 13, 2005 at 10:19 AM 0 replies 1k views
Original Post
Paul7
Paul7
Ive created a table as follows:

table= {}
table.a = {x = 20,  y = 10, z = 42, radius = 10}
table.b = {x = 120, y = 20, z = 12, radius = 20}
table.c = {x = -20, y = 30, z = -22,radius = 4}
table.d = {x = -100,y = 20, z = 67, radius = 25}
table.e = {x = 35,  y = 20, z = -72,radius = 10}
table.f = {x = -250,y = 40, z = -22,radius = 15}

I`m trying to access each indiviual element in turn using a function call from c++. I then select the next element in the table using the next function. The problem with this is that it doesnt return the table elements in sequential order. I get a, c, b, e, d, f instead of a, b, c, d, e, f. Anyone have any suggestions on how to solve this problem? thanks
corysama
corysama
For the most part, Lua tables are hash tables. Hash tables allow very fast indexing with arbitrary keys, but they do not guarantee the specific order of items when traversed linearly.

If you need iterate in a specific order, use numbers as your keys instead of strings. That way you can iterate over the table like you would a C array.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.