| 07-05-2006, 04:31 AM | #1 |
Pretty simple really, i know how to use local variables, but i have a simple question: Do local variables cross over triggers? I'm trying to create a channeled healing spell, i was originally going to use a negative life drain, but it turns out that theres no way to stop it transferring life, so after searching for a channeled damage ability, of which i could only find Aerial Shackles, which stops the target from doing anything, i decided i'd have to trigger it. If i can't use local variables across multiple triggers, how could i trigger such a spell? Keeping in mind that if i have to use JASS, the only thing i want to use it for is to identify the caster and the target. |
| 07-05-2006, 04:54 AM | #2 |
You'll need something like this. I haven't tried it myself, as I use the direct JASS version, so I wouldn't know about leaks and such. |
| 07-05-2006, 05:59 AM | #3 |
I need to nullify local vars after their used correct? I assume since this just lets me use local vars in GUI, all i have to do is nullify them once their not needed and that solves leaks, or am i going off on the wrong track? |
| 07-05-2006, 07:55 AM | #4 |
Are you refering to the link Alevice gave you? That doesn't let you use local vars in GUI, it lets you use "Local Handle Variables", which is just a name for a JASS system that allows you to store data for a specific object (unit, timer, trigger...). That's different from local variables because the data stored there is object-specific, rather than function-specific like the local variables are. |
| 07-05-2006, 09:01 AM | #5 |
To answer your question, if you had the line: Trigger: Custom Script: local unit MyUnitThat would create a new variable EVERY time the trigger is ran, it dosent find the old 1 then edit/change it. local in a way means it creates a new variable, and global means it keeps the old 1. Locals insure mutli-instancability. |
| 07-05-2006, 09:49 AM | #6 |
Locals are what i'm after then. What i have is a trigger that starts a timer when the spell channeling begins and one that stops and destroys the timer when the spell channeling ends. I then have a 3rd trigger which goes off every time the timer expires, which heals the unit stored in another variable based on the attributes of the caster from a second variable. Ovbiously, if i want to make this multi-instancable, i can't use global vars, what i want to know is, without delving into 'full' JASS and by using lines of custom script, can i use local variables across triggers? |
| 07-05-2006, 10:14 AM | #7 |
No... that's why they are called local and not global. A local can only be used within its function. |
| 07-05-2006, 10:42 AM | #8 |
Thats why you should use local handle variables for it. You store all data to the timer and then you retrieve it again when it expires. |
| 07-05-2006, 10:55 AM | #9 |
Right, thats what i thought i'd need to do. So that WE thingo gives me triggers to put said data into timers, how do i get the dang stuff back out again? |
| 07-05-2006, 11:14 AM | #10 |
The tool & map Alevice pointed to has a ,*drumroll*, Readme. |
| 07-05-2006, 11:47 AM | #11 |
Exactly, Alevice's link is a tut on Local Handle Vars. Its about using H2I, I2Timer, I2Unit, I2Whatever else. Store the int to a GameCache with the timers id, get it back later, the int when using I2Whatever gives you back the thing you stored. |
| 07-05-2006, 12:19 PM | #12 |
Huh, i read the readme and all it did was tell me how to install the proggy. Guess i need to look through it again. -EDIT- The readme definitely just tells you how to install the proggy, nothing about retrieving said values or anything like that. |
| 07-05-2006, 04:40 PM | #13 |
lets say you want to store an integer to it: JASS:function blabla2 takes nothing returns nothing local timer t = GetExpiredTimer() local integer i = GetStoredInteger(GC(), I2S(H2I(t)), "bla") //gets integer from key "bla", needs the function GC() to return an initialized gamecache variable call PauseTimer(t) call DestroyTimer(t) set t= null endfunction function blabla takes nothing returns nothing local timer t = CreateTimer() call StoreInteger(GC(), I2S(H2I(t)), "bla", 5) //Stores integer 5 on the key "bla", needs the function GC() to return an initialized gamecache variable call TimerStart(t, 2, false, function blabla2) //starts timer which will expire in 2 seconds set t = null endfunction |
| 07-05-2006, 05:14 PM | #14 |
As I said, I haven't used the GUI version, but I'll describe how the JASS version works: Say you have variable Kills (of type integer, duh) in trigger KillCount, and you need that value on trigger CalcPoints. You will need a (preferably) local variable of type trigger on KillCount, which we will name T; we then set T to the CalcPoints trigger. Then, you attach Kills in T. How? Using the Local Handle Vars system. You store Kills with the name "Kills" (it is suggested to use the same name of the original variable) in T. Then on CalcPoints, you retrieve an integer value named "Kills" from the Triggering Trigger. Since T pointed to CalcPoints, and triggering trigger points to CalcPoints, the value retrieved will be naturally the same you stored a step above! The same can be applied for more stuff than trigger, call it units, timers, anything derived from handle. I hope you get the idea. |
| 07-05-2006, 07:37 PM | #15 |
Another Example: JASS:globals gamecache udg_GC = null endglobals function GC takes nothing returns gamecache if(udg_GC == null) then call FlushGameCache(InitGameCache("GC")) set udg_GC = InitGameCache("GC") endif return udg_GC endfunction function H2I takes handle H returns integer return H return 0 endfunction function I2Unit takes integer I returns unit return I return null endfunction function ChangeUnitCustomValueAfterTime_End takes nothing returns nothing local timer t = GetExpiredTimer() local string St = I2S(H2I(t)) local unit TheUnit = I2Unit(GetStoredInteger(GC(), St, "ChangeUnitCustomValueAfterTime_Unit")) local integer value = GetStoredInteger(GC(), St, "ChangeUnitCustomValueAfterTime_Value") call SetUnitUserData(TheUnit, value) call FlushStoredMission(GC(), St) call DestroyTimer(t) set t = null endfunction function ChangeUnitCustomValueAfterTime takes unit whichUnit, integer value, real Wait returns nothing local timer t = CreateTimer() local string St = I2S(H2I(t)) call StoreInteger(GC(), St, "ChangeUnitCustomValueAfterTime_Unit", H2I(whichUnit)) call StoreInteger(GC(), St, "ChangeUnitCustomValueAfterTime_Value", value) call TimerStart(t, Wait, false, function ChangeUnitCustomValueAfterTime_End) endfunction I will read what it does. Fully. Mini tut: Explanation for H2I: It converts a handle (h) to its ID. Every handle in the game has its special unique id. This gets its id. The I2Unit reconverts a ID into the unit. So we can now store the infomation of a unit, as a integer, then get it back later! How amazing! Now. Thats what infrane pointed out. To step it up a notch though. Instead of storing it as 2 strings, we store it as 1 and store the other string as the base id for a timer! Now. This is where things get handy, i will explain the functions now. We will start from the bottom, because thats how they work. ChangeUnitCustomValueAfterTime: We create a timer We get the timers ID and convert it to a string. Now, complicated: JASS:call StoreInteger(GC(), St, "ChangeUnitCustomValueAfterTime_Unit", H2I(whichUnit)) So in fact, it 'attaches' the unit to the timer. Then we store the new value to the timer in the next line down. We then start the timer, it lasts Wait seconds, and when its done, it will automaticly run function ChangeUnitCustomValueAfterTime_End. Now for that function. First we get the timer back, GetExpiredTimer() We get the timers id to a string. We get the unit, which is a bit complicated. Forget the I2Unit for now, the GetStoredInteger uses the timer as 1 of the strings, and the other as "ChangeUnitCustomValueAfterTime_Unit". This will then return the units ID as we stored it before. We then use I2Unit to retrieve the unit. Welcome my friend, to local handle vars, passing variables into other functions without globals. If that sounded complicated, just post or pm, i will help as much as i can. |
