• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Variables

Status
Not open for further replies.
Level 4
Joined
Jun 11, 2004
Messages
50
i need to know how to create variables, since i want to have my heroes dying and revive at the level they died. i heard i needed a variable for it and that it won't happen automatically, but i don't know how to set one up.

i've looked at the variable editor and i can add variables, but i don't know what i should call them, and i don't know how to get them to refer to what i need...it just says "variable name" and i suppose i can call it anything i wish? or are there requirements? and then a checkbox for array, and a field for size, and i messed with it some to see if just experimenting with it would help point me in the direction i needed to go but i had no luck with it.

any help is much appreciated. very, very, very much appreciated. i'm using a custom map i like to try and make a different version of it, but i don't want to just cut and paste all the triggers to get my game to function the same as this other game. i only want certain stuff...so i figure i need to learn some about setting up the triggers myself. i think i am capable of doing it, if i could just nail down this variable problem.
 
Level 13
Joined
Jan 9, 2004
Messages
1,037
Variables are very easy to understand. Basically, you can call it what ever you want (there is a character limit, I'm not sure exactly what it is though). The next field defines what the variable will hold, so if it's a unit you'd set it to a unit variable. In your case you would want it to hold the heroes level, so you would set it to a integer variable. An array-type variable holds more than one thing, so, for example, if you were making a TD and you wanted to spawn a lot of unitsand hold them in variables, it would take foreve to make and set all those variables, so you would make an array-type variable and set it to the amount of units you want it to hold (once again, there is a limit, but I'm not sure what it is). For your case you probably wont need a array-type variable.

I hope I helped you out.
 
Level 13
Joined
May 5, 2004
Messages
1,330
Name could be any, the variable type is important.

e.g. for your heros, you need a variable of type "unit"

a trigger to refer to it is

Set Variable

-> Set [Your Variable] = [e.g. Last Created Hero]

From now on the variable refers to this hero and in other triggers you can always refer to the variable if you wanna refer to your hero.

Edit: ARgh, oz02, how fast do you type?
Edit2 (by oz02): LOL. Not that fast - you must be slow :lol: .
 
Level 4
Joined
Jun 11, 2004
Messages
50
ok so if i am spawning 10 different types of monsters i would create an array sized 10 and then make a trigger to set variable unit1 = monster1, variable unit2 = monster2, and so on?

then i could spawn unitmonster1 through 10 with the variable, but how is that different (or more specifically, more efficient and useful) from just "unit - create" and then manually selecting the monsters?

and for hero level...if i wanted a max level of 20 for heroes, and there were 10 heroes to choose from, i would create variable array with a size of 10? or 20? i'm positive if i can just make the link to how it works in my mind, the whole system will be understandable...

its like when i was taking piano lessons, i just couldn't understand how my music teacher knew a certain note = C. or why that other one was C sharp. it just didn't make any sense to me. then one day she said, "you don't ask why the letter A is A, do you? a note in this position will ALWAYS be C." and then i just got it. it made things alot easier after that. i'm feeling like this is the same situation, and i just need some link to make it all click into place.

i guess what i am wanting to know is what exactly is stored in the variable. the hero itself, or its level? if its the level, will i also need to create variables for what items its carrying? what about his dmg/armor/str/agi/int...

most of what you guys made sense, but something is still missing...let's say there is a delay in when the hero is revived. if the situation is that the variable stores the hero itself, my hero variable only needs to be "1" in size, and all the other information is automatically taken care of by the game engine. so my "variable" dies, and then i specify the amount of wait time until revival, and then specify "create variable at specified location." so my hero revives, and his stats/levels/items are all intact, is this a correct assumption?
 
Level 13
Joined
Jan 9, 2004
Messages
1,037
Wow, that was a long post. Ok, here's the answer:

1. You would use the Unit - Create trigger, but after you create every unit you would use the Set Variable trigger to set unit1 = (last created unit) for ever unit that you created. See, the thing with variables is that usually they are empty 'pockets' when you create them, and you have to put something inside them. So, after you create your units you are putting the monsters inside them by using the Set Variable command.

2. As for the Hero thing, I would say the best thing to use is the Revive command, and create one variable to hold the dead hero. I'll give you the triggers to use. First, make a unit variable for the hero, i'll call it Hero.

Now create the following trigger:
Code:
Events
    Unit - A unit Dies
Conditions
[insert conditions that you want - for example, checking if the unit dying is the hero you want to revive]
Actions
    Set Hero = (Dying unit)
    Wait [number] seconds [<-Use this if you want a delay]
    Hero - Instantly revive Hero at (Position of (Dying unit)), Show revival graphics [you can also Hide the revival graphics]

I hope this helps you out.

EDIT: You actually don't even need to use a variable if you put it all in one trigger - just change the Hero - Instantly revive Hero at (Position of (Dying unit)), Show revival graphics trigger to Hero - Instantly revive (Dying unit) at (Position of (Dying unit)), Show revival graphics. Sorry for the mistake.
 
Level 4
Joined
Jun 11, 2004
Messages
50
hey that's pretty badass oz02, looks like i won't need variables at all to revive my heroes when and where i want. awesome! =)

and i think i have a basic idea about variables now, and i can probably do most of what i want. hopefully with practice it'll eventually sink in. thanks :D
 
Level 4
Joined
Jun 11, 2004
Messages
50
alrighty, i tried making a count down timer window to show how long until the dying dude is revived, and it asked me for an "index" number...i just set the index number to the player number(owner of (dying unit)) but when i tried to do that same thing with a special effects array, i couldn't. it asked for an index number but there was nothing remotely appropriate (from what i could tell).

if an array is for multiple items, why am i asked for an index number in a special effects array (or any array for that matter)? why isn't the "last created special effect" assigned a random index number? i thought that was what arrays were for, anyway, to store a specific item of a type of which large numbers will be used/in play at any given time. but it wants me to pre-set the index number. which makes no sense to me...

so if i just make a regular special effect variable, and then ask my trigger to set SFXvariable = (last created special effect), wouldn't that be a single value? if so, when multiple triggers are activated that set SFXvariable = "last created special effect" to me appears as if some variables would get overwritten and then many commands to destroy last created special effect, or "destroy -SFXvariable" would miss the special effect they are supposed to destroy. in any case, i'm rather confused. variables aren't as easy as you all say!

basically, i think i have to be totally not getting this variable thing. but i do appreciate you all guys trying to help me get it! oh well.
 
Level 13
Joined
Jan 9, 2004
Messages
1,037
The way an array works, is that its like the variable except with more than one pocket. So, when you do the Set Vairable triggger it needs to know which 'pocket' (index) of the array it should store the special effect/whatever in. So, you pretty much have to keep track of which pocket holds which.

I hope I'm making this clear...
 
Level 4
Joined
Jun 11, 2004
Messages
50
yeah, i can tell you guys are being as to-the-point as you can (and incredibly patient). i think i am just asking the wrong questions.

lemme try again. cuz i know what a variable is. a variable is something like "X" which is a changeable value. uh, basically. its not set like "teapot" is in the kitchen, or "refrigerator" is in the kitchen. its like...there is "x" item in the kitchen and "x" could be anything in there...er...oh well.

so anywho, let me get to the damn point. if a special effect variable is X, and an array is like...X1, X2, X3, i think what i need to know is if i have 2 (or 10, or 20, or a gazzillion) triggers that need set SFXVariable = (last created special effect), and they are all just regular special effect variables (not arrays) and somehow, miraculously, they are all activated at the same time and they go to perform action

-special effect: destroy (SFXVariable), will they all be referring to the same "x?" i.e. will all gazillion triggers try to destroy the same variable, or will they be destroying just their own SFX variable and i dont need to create arrays? here's the part i'm getting confused. maybe. maybe i should just say to hell with if i muck up the works with a bunch of lag and just move on! hah.

god, i hope i explained that okay. at this point, if you guys don't feel like responding that's cool...i'd probably be tired of me by now if the shoe were on the other foot =p.

i'll keep thinking on it - one day i'll get it.
 
Level 13
Joined
Jan 9, 2004
Messages
1,037
Just to clarify what TheWickerMan said, when you create a variable through the regualr GUI, it will be considred in every trigger that you use throughout the whole map. Therefore, you will be unable to use it at the same time in different triggers. That's why you have to use an array to hold one for every trigger. On the other hand, you could use a local variable via JASS, but thats a whole different story, it requires knowing JASS (Blizzard's scripting language).
 
Level 8
Joined
Apr 3, 2004
Messages
507
There's a way to fake having a global treated as a local, but it's mostly for use in erasing memory leaks.

As far as having an array value for every trigger, that's not necessary. Triggers will never overlap unless there's a game-wait or other kind of wait in the trigger. Also, if there *is* a wait in it, multiple instances of the same trigger could be running at the same time, which means they'd be using the same index of the variable.

Long and short is, very rarely will a global run into itself, except in unusual situations for a beginning triggerer. However, it's very useful to use a variable array to store values based on player number, just so they can be retreived by player number later.

Pretend you had a unit variable array that you were using to store every player's hero in. If each player has exactly 1 hero, you can store Player 1's hero in your array in index 1, Player 2's in index 2, etc. That's a useful way to use arrays.

So,
unitArHero[1] is player 1's hero
unitArHero[7] is player 7's hero
etc.

And when you need to get a hero, you can say
"Give me unitArHero[Player number of Triggering Player]". That's how it makes life easier and your code more attractive to the opposite sex.
 
Status
Not open for further replies.
Top