OK, this is my 6th tutorial...it is independent of the "transitioning from wc3 to sc2" series so you don't need to have read those.
Also its a mini tutorial. So read this real quick and get back to map making!
So..What the heck IS an array?
To put it simply, an array lets you store a ton of values in one variable. So lets say to want to have 10, 20, or even 100 different regions all assigned to variables. Having 100 variables = huge mess. The answer? Use an array. So go to the trigger editor and right click. Create a variable just like normal, set the type to "region". Now, check the box that says "array". set ONLY the top box to 20. leave the others at 0. If you fill in a second box, the array becomes 2 dimensional, 3 boxes = 3 dimensional array, etc. Normally you will only need to use the top box. SO anyway, setting this to 20 makes the variable have 20 'slots' in which you can save variables. When you refer to the variable later, you need to indicate which 'slot' you want to use. (See the picture at the bottom)....
So when you set a variable, for example, lets say you have your 20 regions. Use "set variable". Set the variable to the region array you made. Then you will need to set the slot to 1. So this means the 1st slot in the array will be set to whatever region you put in. Then you can just copy the action and change the 1 to a 2, and then set that to your second region. Now your 1 variable holds all 20 regions inside of it.
Okay..so arrays are good for organization, but is there any REAL use for them?
Yes. Lets say you have a mutliplayer Shooter game. You have 1 trigger for shooting bullets.So you say
event- player clicks mouse (or a button, whatever...)
NOTE- I used modify variable instead of set variable because it works better for this kind of map, but don't worry, set variable works also
So why have triggering player as the slot? Simple. You make an array for the ammo left. Player 1 has slot 1, player 2 has slot 2, etc. So when player 1 shoots, he is the triggering player. Therefore, the ammo in slot 1 is modified. This way you only need 1 trigger instead of 1 for each player. In some situations, arrays are the only logical option to use.
The End
Ok..Hopefully that helps you out a bit. Good Luck with your maps!!
Question: Are arrays in the Galaxy editor numbered like typical arrays? I.e, do they start at zero (Array of size 4 has Array[0] through Array[3])? I think I've assumed they were, but I figured I'd ask.
Arrays created using the GUI interface in SC2 have 1 more number than what you set. so an GUI created array of size 4 has array[0] through array[4] as possibilities.
This is because blizzard assumed that people who work with these arrays don' t have to know how normal arrays (that programmers use) really work.
ps. arrays created in galaxy code work as programmers would expect.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
OK, this is my 6th tutorial...it is independent of the "transitioning from wc3 to sc2" series so you don't need to have read those.
Also its a mini tutorial. So read this real quick and get back to map making!
So..What the heck IS an array?
To put it simply, an array lets you store a ton of values in one variable. So lets say to want to have 10, 20, or even 100 different regions all assigned to variables. Having 100 variables = huge mess. The answer? Use an array. So go to the trigger editor and right click. Create a variable just like normal, set the type to "region". Now, check the box that says "array". set ONLY the top box to 20. leave the others at 0. If you fill in a second box, the array becomes 2 dimensional, 3 boxes = 3 dimensional array, etc. Normally you will only need to use the top box. SO anyway, setting this to 20 makes the variable have 20 'slots' in which you can save variables. When you refer to the variable later, you need to indicate which 'slot' you want to use. (See the picture at the bottom)....
So when you set a variable, for example, lets say you have your 20 regions. Use "set variable". Set the variable to the region array you made. Then you will need to set the slot to 1. So this means the 1st slot in the array will be set to whatever region you put in. Then you can just copy the action and change the 1 to a 2, and then set that to your second region. Now your 1 variable holds all 20 regions inside of it.
Okay..so arrays are good for organization, but is there any REAL use for them?
Yes. Lets say you have a mutliplayer Shooter game. You have 1 trigger for shooting bullets.So you say
event- player clicks mouse (or a button, whatever...)
actions- modify variable "ammo_left [triggering player]" -1
NOTE- I used modify variable instead of set variable because it works better for this kind of map, but don't worry, set variable works also
So why have triggering player as the slot? Simple. You make an array for the ammo left. Player 1 has slot 1, player 2 has slot 2, etc. So when player 1 shoots, he is the triggering player. Therefore, the ammo in slot 1 is modified. This way you only need 1 trigger instead of 1 for each player. In some situations, arrays are the only logical option to use.
The End
Ok..Hopefully that helps you out a bit. Good Luck with your maps!!
Reserved Space<<<
As always, let me know how to improve or ask questions here.
@zeldarules28: Go
Question: Are arrays in the Galaxy editor numbered like typical arrays? I.e, do they start at zero (Array of size 4 has Array[0] through Array[3])? I think I've assumed they were, but I figured I'd ask.
I know they start at 0, and I think they also go up the number you enter.
@zeldarules28: Go
Arrays created using the GUI interface in SC2 have 1 more number than what you set. so an GUI created array of size 4 has array[0] through array[4] as possibilities.
This is because blizzard assumed that people who work with these arrays don' t have to know how normal arrays (that programmers use) really work.
ps. arrays created in galaxy code work as programmers would expect.