Tutorial: Arrays

Laosh'Ra

New Member
For those who want to understand arrays:
how do i create arrays?
while making a new variable just activate the "array" box and set the number of possible entries.
to call the different entries you have specify the number of the entry: tinef[1] for the first entry, tinef[2] for the second entry (tinef is the name of the variable).

WTF are arrays anyway???
a common variable has only 1 value. by using arrays its possible to store many values in a single variable. this is useful to create certain dynamic things instead of using copy-paste all the time.

HUH?
heres an example:
10 spawnpoints are created (regions in this case).
a variable named "spawnpoints" is created as array with the size 10.
at the beginning of the map the spawnregions are stored in the array:

Set spawnpoint[1] = frist_spawn_region <gen>
Set spawnpoint[2] = second_spawn_region <gen>

etc.

whatever... now whats the clue with arrays?
besides the overview, arrays have a nice feature: you can replace the index-number with another variable!
instead of using this
Unit - Create 1 Soldier for Player 1 (Red) at (Center of spawnpoints[1]) facing Default building facing (270.0) degrees
u can make it like that
Set randomnumber = (Random integer number between 1 and 10)
Unit - Create 1 Soldier for Player 1 (Red) at (Center of spawnpoints[randomnumber]) facing Default building facing (270.0) degrees

=> 1 unit is spawned in a random spawnpoint

of course u could solve this with mass IFs but this wouldnt work anymore if u make a map with 100 possible spawnpoints.

any other examples?
in case u want to spawn 1 unit in each spawnregion u could make a loop reffering to all arrayentries.
For each (Integer A) from 1 to 10, do (Actions)
Loop - Actions
Unit - Create 1 Soldier for Player 1 (Red) at (Center of spawnpoints[(Integer A)]) facing Default building facing (270.0) degrees

=> the action unit-create is executed 10 times. the value of integer A changes each time so another spawnpoint is used in each step. YES u could just copy-paste triggers instead. but that wont work if u have 100,000 spawnregions (theres a maximum triggerlength :p)

hf
 
Werbung:

Daelin

New Member
Arrays are not dynamic. Dynamic means using lists and pointers. JASS uses pointing values, but you don't dynamically control them (atleast not integers, booleans, strings and reals).

Simple tutorial. I wouldn't call it great! Average IMO, but still an addition to the community. :D

~Daelin
 

Laosh'Ra

New Member
i said you "can create dynamic things". this doesnt refer to the arrays but to the outcome being something 'dynamic' in an everyday-meaning :)
 
Werbung:

Daelin

New Member
I find JASS mostly useful for spellmaking (but not only), maybe because I'm a spellmaker. For this reason, I operate a lot with units, and would probablyneed arrays for units. But if you have unit groups I really suggest you use those instead of arrays, mostly because you can use a lot of native functions with them, and because it is a lot faster. And not only! Unit groups use a single handler, while arrays use multiple, so groups are faster. They are easier cleaned and easier nullified. Mostly, you cannot transmit through parameters arrays (or atleast I didn't try) so groups have this advantage as well.

Of course, I'm referring to JASS now, not to GUI. Yes, in GUI I find arrays better because you can't benefit from functions. But you should really mention this! Or else some people might believe that arrays are useful in JASS as well (thing not that true).

~Daelin
 
Top