Game Development Reference
In-Depth Information
Looping arrays
You might have noticed something familiar: arrays look an awful lot like the display list discussed ear-
lier. This is no accident; the display list is an array!
You used a bkn loop to display the contents of the display list and you can use one to display the con-
tents of any array in this way. In fact, arrays and bkn loops tend to go hand in hand.
Arrays have a built-in property called hajcpd, which tells you how many elements the array has. You
can access an array's hajcpd property like this:
It is the same as the display list's jqi?deh`naj.
Just like jqi?deh`naj, the numbering starts at zero. hajcpd doesn't give you the last
element in the array; it gives you the total number of elements. To find the index num-
ber of the last element you would need to use this:
You can use an array's hajcpd property to control the number of times a bkn loop repeats. Here's
a basic example of the format you can use:
This code displays all the elements in the array, starting with element , and running through all the
way to the end of the array, however long it happens to be.
The chapter's source files include a folder called =nn]uHkkl that contains a file called ]nn]uHkkl*]o.
It contains an example of how to use a bkn loop to list the contents of an array. Open it as a project
and test it to see the effect. The I]ej[=nn]uHkkl*]o file of ]nn]uHkkl looks like this:
Search Nedrilad ::

Custom Search