In Lua, arrays are implemented using tables.
1. array definition:
Self. itemarrays ={}; -- The itemarrays table used as an array
2. Insert a data entry into the array:
Local showitemsprite = ccsprite: Create (); -- creates a showitemsprite object.
Table. insert (self. itemarrays, table. getn (self. itemarrays) + 1, showitemsprite); -- insert showitemsprite into the itemarrays table (our array)
-- The insert position is the length of itemarrays plus 1, that is, the end of the table.
Function for obtaining the length of an array (table): Table. getn (array name );
3. traverse this array:
Local length = table. getn (self. itemarrays );
For I = 1, length do
Local itemsprite = self. itemarrays [I]; -- uses subscript I to retrieve the corresponding elements in the array (the subscript of the table in Lua starts from 1)
If itemsprite ~ = Nil then
-- Operate the itemsprite element in the logarithm Group
End
End