Arrays and Lists

In your games, you’ll have to deal With a bunch of items, bullets, enemies, obstacles, and so forth. To store this kind of data in memory, you will use arrays or lists. You’ll use an array when the number of items is known. Some examples are months, fixed gameplay elements, and inventory items. You’ll use a list when the number of items is unknown and fluctuating (e.g., bullets, flying saucers, and other funny things a video game contains).

Arrays

Create an Array

In Lua, an array is nothing more than a table (see the chapter “Variables, Tables, and Expressions”).

ifig0031.jpg

Then, in the table, we insert data indexed With an integer ...

Get Create 2D Mobile Games with Corona SDK now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.