• Help With Tables
    6 replies, posted
I know how to print specific entries from a table, but how to you print a specific field from a table? [code] thetable = {} PrintTable ( thetable[3] ) [/code] This would print the third entry in the table, how would print a specific field within an entry?
[lua] print( thetable[3] ) [/lua]
[QUOTE=zzaacckk;41054160][lua] print( thetable[3] ) [/lua][/QUOTE] Did not work, and wouldn't that only print entry[3] like I already know how to do? Here is what my table is printing, id like to only grab the positions. [code] 1: class = death pos = -79.018898 292.711700 -12267.968750 2: class = fire pos = -26.074100 577.555115 -12267.968750 [/code]
[lua] for k,v in ipairs(thetable) do local pos = v.pos print(pos) end [/lua]
Works great brandon! Whats the deal with ipairs? I have never seen that before.
It's used for tables that have integers for their indexes that are sequentially incremented, which can be called a hash table. You can learn more about it here: [URL="http://lua-users.org/wiki/GeneralizedPairsAndIpairs"]http://lua-users.org/wiki/GeneralizedPairsAndIpairs[/URL]
Thanks for the documentation I appreciate it.
Sorry, you need to Log In to post a reply to this thread.