| 01-12-2007, 05:11 AM | #1 |
HA! Posted in the right thread this time These are a set of custom functions I'm making. Don't tell me how bad they are, I'm making them for my convienince. Now then. JASS:function DamageOverTimeDamage takes unit damager, widget target, real damage returns nothing call UnitDamageTarget(damager, target, damage, false, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_UNIVERSAL, null) endfunction function DamageOverTime takes unit damager, widget target, real intervaltime, real totaltime, real damage returns nothing local timer t = CreateTimer() call TimerStart(t, intervaltime, true, function DamageOverTimeDamage(damager, target, damage)) call PolledWait(totaltime) call PauseTimer(t) call DestroyTimer(t) set t = null endfunction JASS:call TimerStart(t, intervaltime, true, function DamageOverTimeDamage(damager, target, damage)) That line gives me a syntax error. Any idea why? Getting rid of the function kills the error. It gives all the correct take values, but I don't get why it's not working. |
| 01-12-2007, 05:15 AM | #2 |
JASS:call TimerStart(t, intervaltime, true, function DamageOverTimeDamage(damager, target, damage)) You have to store them seperately and recall them inside of the timer callback. This is where cache storage might be useful. |
| 01-12-2007, 05:19 AM | #3 |
So your saying that the timer callback's function cannot have takes? It has to be like JASS:call TimerStart(t, intervaltime, true, function DamageOverTimeDamage()) So how would I store those values in gamecache? I've never used it, nor had any need to until now apparently. Thanks for helping! EDIT: I have local handle vars. |
| 01-12-2007, 05:39 AM | #4 |
JASS:call TimerStart(t, intervaltime, true, function DamageOverTimeDamage) Those are handle vars, which are basically just wrappers for natives that store to cache using I2S(H2I(...)). The tutorial written by KaTTaNa on how to use handle vars is located here. So basically... JASS:function DamageOverTime_Damage takes nothing returns nothing local unit damager = GetHandleHandle(GetExpiredTimer(), "DamageOverTime_Source") local unit target = GetHandleHandle(GetExpiredTimer(), "DamageOverTime_Target") local real damage = GetHandleReal(GetExpiredTimer(), "DamageOverTime_Damage") call UnitDamageTarget(damager, target, damage, false, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_UNIVERSAL, null) set damager = null set target = null endfunction JASS:function DamageOverTime takes unit damager, widget target, real intervaltime, real totaltime, real damage returns nothing local timer t = CreateTimer() call SetHandleReal(t, "DamageOverTime_Damage", damage) call SetHandleHandle(t, "DamageOverTime_Source", damager) call SetHandleHandle(t, "DamageOverTime_Target", target) call TimerStart(t, intervaltime, true, function DamageOverTime_Damage) call PolledWait(totaltime) call FlushHandleLocals(t) call PauseTimer(t) call DestroyTimer(t) set t = null endfunction The function calls I used can be found in the links provided above. Of course, if you're feeling daring you can study the functions that directly access cache call StoreInteger(...) and use those. They're quicker and more efficient than their wrapper counterparts, but they're generally a bit tougher to grasp mentally. |
| 01-12-2007, 05:47 AM | #5 |
Ah thanks very much Dusk, +candy for you. I will plug this in ASAP. Although its alot longer than I wanted it to be XD.... Oh well, nobody is gonna see that stuff unless they check the Custom Scripts section. Thanks again, I'll remember this. EDIT: Errors at the lines retrieving the units. JASS:local unit damager = GetHandleHandle(GetExpiredTimer(), "DamageOverTime_Source") local unit target = GetHandleHandle(GetExpiredTimer(), "DamageOverTime_Target") "Cannot convert handle to unit" Everything else parses fine though. |
| 01-12-2007, 05:51 AM | #6 |
Notably though, there are a few errors with handle vars I almost forgot to mention -- Nullifying timers you set handles onto seems to cause one of these issues. So try doing it like this instead (This also saves lines) -- JASS:function DamageOverTime takes timer t, unit damager, widget target, real intervaltime, real totaltime, real damage returns nothing call SetHandleReal(t, "DamageOverTime_Damage", damage) call SetHandleHandle(t, "DamageOverTime_Source", damager) call SetHandleHandle(t, "DamageOverTime_Target", target) call TimerStart(t, intervaltime, true, function DamageOverTime_Damage) call PolledWait(totaltime) call FlushHandleLocals(t) call PauseTimer(t) call DestroyTimer(t) endfunction This removes the need to nullify it, and you can just call it like this now -- JASS:call DamageOverTime(CreateTimer(), Source, Target, 0.33, 10., 30) |
| 01-12-2007, 11:16 AM | #7 |
That still didn't fix it, but I think I did. Replaced this: JASS:local unit damager = GetHandleHandle(GetExpiredTimer(), "DamageOverTime_Source") local unit target = GetHandleHandle(GetExpiredTimer(), "DamageOverTime_Target") JASS:local unit damager = GetHandleUnit(GetExpiredTimer(), "DamageOverTime_Source") local unit target = GetHandleUnit(GetExpiredTimer(), "DamageOverTime_Target") Since you were declaring a unit variable, the functions needed to return units. I don't know if it will work this way, but it parsed ok. |
| 01-12-2007, 03:08 PM | #8 |
Oh yeah, lol. You figured it out and I even made some ugly mistypes. My bad, I always have a tendency to not run things throug PJASS before posting. But yeah, you got it. My brain had a momentary lapse, but yeah you'd want GetHandleUnit(...) for those two. I was just cranking away and totally forgot to do that. |
| 01-12-2007, 08:17 PM | #9 |
Ha, no problem. It helps me learn... For some reason, I never understood that system until like, just now. Hm. Well, I'll have to use it more often won't I? Thanks again, you're a big help. |
| 01-12-2007, 08:29 PM | #10 | |
Quote:
We were on the same boat. I couldn't figure shit out of it until I had to implement it. Then it magically became logical. |
