| 11-14-2003, 12:09 AM | #1 |
Hi, I am wondering something about local variables. Is it possible to declare a local variable in the maps header. If not is it possible can I pass local variables to another trigger. I don't want to use global variable because I would need to create a ton of variables. I want to make it so that A trigger creates the local variable equal to that unit when a unit dies, then use the information from the variable in an event for another trigger. The triggers would look something like this Event -A unit dies Conditions Actions -custom script local unit udg_deadunit -Create 1 (Unit type-of (triggering unit)) for (Player (triggering player)) at location of (triggering unit) -custom script set udg_deadunit = GetLastCreatedUnit() -Add event deadunit is selected If I need to do this with a global var I would have to make one for each player and then have it add the event. It would also reset the trigger if a players unit were to die more then one time. With a local variable it would create a new variable every time the trigger was in scope and would delete the variable when it went out of scope. If there is another way to do something like this please let me know It would help a bunch. P.S. If this is in the wrong forum please move it to the right one, I was not sure on where to place it. I am also a newb when it comes to jass, sorry. |
| 11-14-2003, 12:32 AM | #2 |
Your confusing me, what exactly are you trying to do? Events dont use variables, they use a direct reference to the unit itself (the old "cant make an event work on a variable thing"). I suspect your confused and you can do what you want to without using local variables at all. |
| 11-14-2003, 12:38 AM | #3 |
You can use variables in events threw the action "Add Event to Trigger" that way you can have variables in events because the unit is not placed but it changes and the event "Unit is selected" must have a unit in a selected on the map but if the unit is killed its no longer the same unit. That way with a local variable I can set the unit for the player when it dies and the use the action add event to trigger. It also keeps it from having to have multiple variables for each player and each time a unit dies. I hope you understand better now. |
| 11-14-2003, 12:42 AM | #4 |
Couple of problems with your idea. -Local variables dont work on BNET to my knowledge -You could just use an array instead of making alot of Global Variables -Under no circimstances will a event use a variable, unless the GUI is edited so it will. Even if this is the case 99.9% of the time it wont work right. |
| 11-14-2003, 01:00 AM | #5 | |
Quote:
I am guessing you have not used UMSWE 4.0 because right now I am using variables in triggers by useing as I said before the "Add Event to Trigger" I am currently trying to use arrays, but with them I need to make a trigger for each player and I only want to use 2 triggers in what I am working on if I can. P.S. I also have just tested using variables in events. I can send you a small map to show you if you don't belive me. |
| 11-14-2003, 01:05 AM | #6 |
To set the record straight: Local variables work in all Warcraft III games, including B.NET. You can use variables in the Add Event action, but it will only work for what the variable is used for at the time. For instance, if you have a global unit variable UnitA, and make a trigger that sets UnitA to Footman1021, then you use the Add Event action to create a new A Unit Comes Within Range of UnitA event, then another trigger sets UnitA to Footman1011, then the event will always respond to Footman1021. From what you are saying, you ought to be able to do what you want, because although the local variable exists for that function, it doesn't asign the variable to the event, but what the variable responds to. |
| 11-14-2003, 01:06 AM | #7 | |
Quote:
Say a trigger does the following: (Deathknight and paladin could be preplaced... or created... or a bit of both, doesn't matter) Set Unit = DeathKnight Add (Unit) takes damage to (ouch) Set Unit = Paladin Add (Unit) takes damage to (ouch) Trigger ouch now has the following events: e - DeathKnight takes Damage e - Paladin takes Damage c - a - whatever NOT either of the following things that you might expect: e - Paladin takes Damage e - Paladin takes Damage Or e - Unit takes Damage e - Unit takes Damage IF you already understood that, then please say WHAT your trying to do, rather than just how your trying to do it. |
| 11-14-2003, 01:30 AM | #8 |
Exactly what I just said. Except laid out better. |
| 11-14-2003, 01:42 AM | #9 |
Grater, FYI, unit specific events have some added things to them that basic unit events don't like, A unit is selected is not an option but unit(needs specific unit) is selected is. Check it out. I am trying to make a way for a unit that has been killed to resurrected, and then go back to the corpse and by clicking on it while the unit is next to the corpse (unit paused and invun in decay position). When the unit is so called resurrected they will get something for traveling back to there corpse. |
| 11-14-2003, 02:53 AM | #10 |
I Have really no idea what you are saying MisterPeepers. Local variables do work. Its not hard either.They must be defined as the first statements in your function and must be before the set, call, loop, if or any other operator are used. LOCAL VARIABLES DEFINED IN A CONDITION OR EVENT OR ACTION FUNCTION ARE EXCLUSIVE TO SAID FUNCTION. If you define a variable in your event section and expect to be able to call in your action section, expect to be disapointed. |
| 11-14-2003, 02:55 AM | #11 |
Here you go, I did something like I wanted used arrays, kinda thought if I was going to use a global var it was going to have to be using arrays. The next step is to try and remake it with a local variable. I have attached the test map so you can see for your self. Every time a unit dies it stores what the unit is, then it add the event to the trigger saying that when the unit is selected it will display the name. I set it up so you just move the peasant you start with to the swordsman and he kills it and spawns a random level 1 creep move that creep to the swordsman to kill your unit. Click on the units corpse ( unit paused in death animation) this unit will display its name. It will only display the name of the corpse only and not any other unit you select unless it is a corpse. Have fun playing with it. |
| 11-14-2003, 03:16 AM | #12 | ||
Quote:
JUST READ WHAT I/NUMBERS GUY SAID. I assure you "takes damage" can only be used for specific unit event, not generic unit event. Sorry for the caps, I was shouting. Quote:
You dont want a local variable... unless you want a trigger to run in a loop. ie: loop exitwhen (owner of corpse is in range) sleep 1.0 endloop (do whatever) You could use a couple of local variables in the "owner in range" condition and set them with globals before calling the trigger when a unit dies. If you want a selection system you only need to figure out some way to to make a corpse know who it's owner is... local variables will not help you and you dont need them at all, you could use them but it wouldn't achieve anything that cannot be done equally easily with a single global. Heres some possible ways to make a corpse know who it's owner is: Set the custom value of corpse to custom value of owner then see if they match - this number you choose should be unique for each owner thats the only requirement <-- if theres only 1 unit for each player that leaves a corpse, you can use the player number, otherwise just increment the value by 1 each time. Set the custom value of the corpse to the unique UnitID of it's owner - requires JASS/custom script. Some way specific to your map, ie array indexing by unit custom value. You can definitely do it with no JASS at all, or you can do it with some JASS... or lots of JASS. Really depends on how you want it to work, and how much you care about cleaning up memory leaks and stuff. |
