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:
]nn]uJ]ia*hajcpd
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:
]nn]nuJ]ia*hajcpd)-
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:
bkn$r]ne6ejp9,7e8]nn]uJ]ia*hajcpd7e''%
w
pn]_a$]nn]uJ]iaWeY%7
y
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:
l]_g]ca
w
eilknpbh]od*`eolh]u*Ikrea?hel7
lq^he__h]ooI]ej[=nn]uHkklatpaj`oIkrea?hel
w
++`a_h]na]nn]u
lner]par]n[_khha_pekjF]n6=nn]u7
 
Search Nedrilad ::




Custom Search