Arrays

Sk8-tEr

New Member
Reaction score
5
Any1 know where a tutorial that describes arrays is?
Or you can explain it, either way. +rep
 

Curo

Why am I still playing this game...?
Reaction score
109
About half-way down the page here. I did a simple search using the terms "array" and "tutorial". Not hard :p
 

CaptDeath

New Member
Reaction score
103
an array
=
folder of one type of variable
a folder that after 8192[8193 if you count 0] are stored in it it explodes! *boom*

string arrays are commonly used for player names the index[the number in between[] is the player number of the players name its storing
 

Azlier

Old World Ghost
Reaction score
461
It seems that the explanation I gave you has been shredded to bits by the passage of time, CaptDeath :D
 

Curo

Why am I still playing this game...?
Reaction score
109
It seems that the explanation I gave you has been shredded to bits by the passage of time, CaptDeath :D

Things seem to happen like that a lot when it comes to CaptDeath.

Arrays are simple yet too complicated to explain with a simple statement (at least he tried).

The best I can say is that arrays allow you to assign a number value to something in addition to a variable. Because of this, multiple objects can be assigned to the same variable.
 

CaptDeath

New Member
Reaction score
103
--off topic---
wtf did i do?
--on topic--
a another quick tip straight from my .. nvm
on nullifying arrays the whole in most cases
Array depending on what they are can be removed using a integer loop cause the index would be [integer a]
 

Romek

Super Moderator
Reaction score
964
> 8192[8193 if you count 0]
I believe it's 8192 stuff that can be stored in an array.
Indices 0 - 8191.

An array is basically a lot of ordinary variables with the same name, and you use an extra number, called the index, to store and retrieve what you want.
It makes things easier if you want to store multiple things of the same type in 1 variable.

And it also allows looping through stored data.
 

eXirrah

New Member
Reaction score
51
Tutorial on arrays for beginners :)

First of all the array is an array of variables....

there are many types of arrays but in warcraft there are only 1-dimentional arrays which makes explanation easier.

What is 1-dimentional array: storage of variables of the same type
in 1-dimentional arrays the variables can be explained as a list
Example:
Code:
array -> type unit
  variable 1 -> type unit
  variable 2 -> type unit
  variable 3 -> type unit
  ....
  variable N -> type unit
All the variables in the array must be of type as the type of the array is.
The maximum size of an array is 8192 in warcraft so N cannot exceed 8192.

Usage of array: in computer language it is common the first index to be 0 except of 1. This can be a bit confusing cause if you set an array to have 5 elements the maximum index of the array will be 4

Array index: every array comes with an index(array[index]. example variable - Unit (array with 5 elements)
Code:
array:
  Unit[0] -> the first variable in the array
  Unit[1] -> the second
  Unit[2] -> the third
  Unit[3] -> the fourth
  Unit[4] -> the fifth
the array of the example has 5 elements but it's last index is 4 because it has 0 index, I state this so people don't get confused!

Storing variables in an array: you can store multiple variables in an single array and call them at anytime you need them.
Example
Code:
In this example three variables will be store in an array variable

var1(type Unit) = Peasant 1
var2(type Unit) = Peasant 2
var3(type Unit) = Peasant 3
var4(type String) = "some string"

array(type Unit)
  Set Unit[0] = var1
  Set Unit[1] = var2
  Set Unit[2] = var3
  Set Unit[3] = var4 <- impossible, var4 must be of type Unit to be stored in array of type unit

It is not neccessery to store variables in array, you can store values as well like
  Set Unit[3] = Random Unit from Unit group
  Set Unit[3] = Random point in region<- impossibe, cannot store variable of type point in array of type unit
all the three variables var1,var2,var3 are stored in the array. To call these variables you need to just select the right index of the array
Example:
Code:
If you want to call a variable from an array:

anyvar(type unit)
anyvar = Unit[1]

anyvar(type String)
anyvar = Unit[1] <- impossible cannot store value from array of type unit in variable of type string

If you want to use a value from an array in some function:
example function -> Unit - Remove

Unit - Remove Unit[1] from the game
Game- Send message to all players Unit[1] <- impossible ....
Common usage of arrays:
1. Loops
It is very simple to do loops with arrays cause you just need to set the loop variable as an index of the array and thus you will be able to circle through the whole array
Example
In case you search for Peasant 2 in the array Unit
Trigger:
  • For each (Integer A) from 0 to 4, do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Unit[(Integer A)] Equal to Peasant 2
        • Then - Actions
          • -------- The unit is found in the array under Index A = 2 --------
        • Else - Actions
          • -------- The unit is not found in the array under Index A different from 2 --------

Of course there are many type of arrays not just Unit. For example the array could be of type Real, Point, String, Unit Group .... etc.

2. Array with base index 0
Somethimes people use the 0 index of an array to set some value as base. For example the Real array is of type real with size 5(has 5 elements).
Example: You can set Real[0] to some base value like minimal distance between two units. Then you set Real[1-4] to the distances between 4 units. If you want to check if the distance between some of the unit is smaller than the minimal:
Trigger:
  • For each (Integer A) from 1 to 4, do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Real[Integer A] is less than Real[0]
        • Then - Actions
          • -------- The distance between the units is smaller than the minimal one --------
        • Else - Actions
          • -------- The distance between the units is eather the minimal one or bigger than the minimal one --------

This is used if the minimal distance between units is changing all the time, i.e. Real[0] is changing all the time and you need to check whatever the units are placed on distance smaller or bigger than the minimum.

Conclusion : Arrays are no more than a storage for variables of the same type which gives the user confort in using variables.

Doh.... with a little edit here and there this could look like real tutorial :)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top