| 01-10-2004, 06:44 PM | #1 |
K a question ive had for awhile... What are variables and what are they for? Ive had someone tell me that theyre used to store data or something, but they never completely explained it. Also, whats an array? Ive almost always done things the long way (without variables), and never really understood their purpose. Also im a bit of a trigger noob :) Thanks. |
| 01-10-2004, 07:39 PM | #2 |
Variables are are positions in memory, an example would be 0x0FA31F. This value in your computers memory can be called upon by it's name, whatever you call it. Different variable types hold different kinds of data in them that you store and access later in your program. A variable of type int can only hold integers, while a variable of type float can hold decimal places and whole numbers. Here is an example of that: float life = 10.546; Whenever I call upon the variable life it will give me the value 10.546. An array is a variable with multiple values stored in it. An example would be: int maxLife[10]; That would be a variable of type integer called maxLife that can hold ten different value at one time. I could store a value in maxLife like this: maxLife[2] = 10; maxLife[8] = 4; Now when I call upon maxLife[2] it would have the value 10, while maxLife[8] is holding the value 4. (did you want a description of warcraft 3 stuff or just in general?) |
| 01-10-2004, 07:42 PM | #3 |
Lol.. WCIII stuff please :) im utterly confused already. |
| 01-10-2004, 07:52 PM | #4 |
K, sorry if I'm not explaining very well. Ok, warcraft 3. In warcraft 3 there are many different variable types. As I said above different variable types hold different types of data. A variable of type integer could hold an integer value. In your trigger if you had an integer called maxLife you could say "set maxLife=10" and then the value stored in max life is 10. You could then say "set life of (last created unit) = maxLife" and that unit's life would be set to 10. A variable of type Unit stores a specific unit, for example a unit variable called exampleUnit: Actions: create 1 unit of type (footman) for (player1) at (center of (playable map area)) set exampleUnit = (last created unit) New Trigger Run afterwards Actions: move exampleUnit to (center of (playable map area)) This set of triggers would move the footman saved in exampleUnit to the center of the map. |
| 01-10-2004, 07:56 PM | #5 |
And if we want to get into confusing. War3 memory is stored in a stack heap. Strings, booleans, and handles all stored in positions somewhere in there. What makes this interesting is the Return bug allowing you to effectively typecast variables. Letting you use a unit var to store an effect and an integer to store a string... Ah the magic of the return bug. |
| 01-10-2004, 08:06 PM | #6 |
You basically use variables to determine anything that changes in the game. Like setting 'VarName1' equal to "Last created unit" which is impossible to do otherwise. Since the unit isn't created yet, you cannot pre-select it in the WE. |
| 01-10-2004, 08:12 PM | #7 |
Well guys im now sorta understanding :) Im sure ill understand this more sooner or later, but thanks for the info. Now ill try to finish my map... |
| 01-10-2004, 08:18 PM | #8 |
Just mess around with all the types of variables. It will come to you. And remember, any of the variable types you can't understand, just go to dictionary.com and look up the variable type. Understanding what something means is the first step to mastering it's abilities. |
