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.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top