• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Variables Scare me! Help!

Status
Not open for further replies.
Level 4
Joined
Jul 9, 2005
Messages
49
Ok....I opened a few hero arena maps to learn how to trigger the leaderboard, kills, victory/defeat conditions, duels, and creeps to finish my map. But ALL those use varibles.

First of all how do I know what to name them, how do I know what it does?

varibles confuse me sooooo much. I tried poking deeper in them and it confused me more. What are their purpose, how do they work, when do I use them, how do I use them in a hero arena, ugh the list goes on. Please someone first explain how they work??
 
Level 22
Joined
May 11, 2004
Messages
2,863
You can name variables whatever you want. They are not like Jass where everything is sensative.

Variables are bsically there to save time and effort in triggering. rather then making 20 triggers per hero, you can make one variable per player and get the same job done.

Basically, you create a variable, then assign it to something. Such as a unit variable to a unit you created. Create the unit, then set the variable, such as "set (unit variable name) as last created unit." After that, you smply use the variable in a trigger and it will always refer to that unit regardless of conditions.

For hero defense, when a player picks a hero, a variable can be set for that hero, so whenever a player springs a trigger, it checks for that variable, rather then checking for whichever hero he has and have to do a hundred triggers to cover each hero combination that player couldve picked when issuing conditions.
-VGsatomi
 
Level 4
Joined
Jul 5, 2005
Messages
140
i would make a variable (type real) that would add +1 every time you kill a hero unit....and name it KilledPL1 , KilledPL2 etc... (PL1 , PL2 ... player 1 , player 2 ...) so the trigger will select the 2 players with most kills from each team...

as i said in my previous topic im pretty busy right nw so maybe later
 
Level 6
Joined
Mar 18, 2005
Messages
153
i think arrays are a bit complicated to start with... well there are many different types of variables. almost ANYTHING can be saved in a variable. there a boolean variables (which are simply true or false) integer (-2, -1, 0, 1, 2...) real (-2.345, 1.2343, 3, 3.5...) and strings which are used to save text (e.g. names). besides those basic types regions, units, unit-types, cameras, sounds, buffs, quests and a lot of other things can be used as variabletype. as said before you have to declare them with "set variable". instead of entering a certain value you can sometimes pick an object from the map (e.g. a unit) or from a list (item, unittype).
you can make some kind of "library" at mapinitialization to define the initual values and the constant values. e.g. if you have a certain value which is used a lot of times in the triggers but you also have to change it a lot (for balance or whatever) you might want to put it in the initialization for more overview and less work to change the values.
anyway, here are some examples for common usage of variables:
integer: to count the number of certain events, to have a certain value to compare the number of units or players in a group, as ability or herolevel, as expvalue, as hitpoint or mana PERCENTAGE, as arrayindex, as variable for "for"-loops
real: as hit- and manapoints (although displayed as integers they have REAL values), as value to be added to herostats, as coordinates for a point
string: as displayed textmessages, as names for almost anything, to analyze chatcommands, as password/savecode
as for the other types of variables: they are often used to save the "last created ..." sound for example so you can stop the sound even later (without saving it you just have "last created sound" as value to modify)
however i think you might search for some examples. ill do that sometime but i just noticed that i got only 20 mins left till i have to go to school so cya XD
if requested ill also explain the versatile usage of arrays and loops.
 
Status
Not open for further replies.
Top