| 12-23-2002, 12:51 AM | #1 |
Guest | What are arrays and how are they used? I know all about variables and how they work, and I understand arrays are groups of variables, but Im looking for some one to shed some light on them for me. perhaps a good example of when to use them |
| 12-23-2002, 12:58 AM | #2 |
An array.... how to explain it this tiem.... :) Ok let's say you have lots and lots of quests. You could make lots of quest variable like this... QuestA QuestB QuestC QuestD QuestE Or....you could make a quest variable an check the "array" button. Now when you pick a quest to use in a trigger, you select the quest array variable, and it will show this... - - - Quest [?] - - - Now click on the ''?'' and put almost any number you want in. Probably easier to start at 1 and go up (you can use 0 too.) Now, you decide you want to make another quest. Instead of making a quest variable, just use the array and make it this... - - - Quest [2] - - - Tada! Much easier. You can use one variable and with as many quests as you want. Does that explain it? |
| 12-23-2002, 01:05 AM | #3 |
Guest | ok, that makes sense. when I want to recall the quest in your example, for what ever reason, I just tell it which number in the array it is. Is this correct? And say I wanted to recall every variable in the array in one trigger, I assume that theres an easy way. An example is I want a trigger event that happens exactly the same for each player. instead of wrtiing in up to twelve different events in the same trigger, I can have it use the array which would make it a shorter process. Is that also correct? |
| 12-23-2002, 02:09 AM | #4 |
yes |
| 12-23-2002, 02:36 AM | #5 |
Arrays can be useful since they are referred to by number. For example you could have a trigger refer to the variable, "Array(random integer between 1 and 5)" so it will go to one of your arrays randomly. This is just one very simple way you can use arrays, there are many other uses beyond the fact that they keep things organized. |
| 12-23-2002, 06:23 AM | #6 |
Guest | groovy! |
| 12-23-2002, 01:00 PM | #7 |
Another key use of Array's is the For each integer A action. Say you had 5 units in a unit Array (Unit[1] Unit[2]... etc.). To do something for all of them at once, you can use the action 'For each integer A from 1 to 5, do action' - where the action could be - 'Set life of Unit[(IntegerA)] to 200' Which would then make every unit in the Array have 200 health :}. You could also make it, say, 2-4, which would then mean that all units in the array except 1 and 5 get 200HP. This shows it's advantage over a Unit Group. Gl hf! |
| 12-23-2002, 05:49 PM | #8 |
Guest | Wow, Im starting to feel silly for every do it the other way. They just seemed to complicated at the time. |
| 12-23-2002, 06:01 PM | #9 |
Okay arrays are basically variables that can hold multiple values, which can save massive amounts of code. Two special arrays must be initialized a little bit differently, for example the timer array and the unit group array. set udg_TimerArray[1] = CreateTimer() set udg_TimerArray[2] = CreateTimer() set udg_GroupArray[1] = CreateGroup() set udg_GroupArray[2] = CreateGroup() |
| 12-23-2002, 06:28 PM | #10 | |
Quote:
Don't feel silly, I took a programming class and hated them cause I couldn't understand them. So I just defined tons of variables each time. And I missed out on alot of stuff you could do with them. I started taking another class. Java and it finally clicked. Now I try and use Array's whenever I can and can do some awesome stuff. I am glad the Forum goers here were able to help. We have the best of them :). Kudos to all those who helped and congrats to Logic DKSlayer |
