HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Alternative to Polled Wait?

08-10-2009, 12:13 PM#1
thehellman
Was wondering if anyone had a function that worked like Polled Wait except wasn't horrible coded?
08-10-2009, 02:45 PM#2
Cheezeman
Use a timer with TimerUtils. It's a bit tricky (you have to save all your data into either structs or hastable, then attach the struct/parent-/childkey to the timer), but it's not horribly coded.

-------- Edit --------
Maybe an example would help.
Collapse JASS:
globals
    hashtable MyHash
endglobals

function KillCaster takes nothing returns nothing
    call KillUnit( LoadSavedHandle( MyHash, 0, GetTimerData(GetExpiredTimer()) ) )
endfunction

function Actions takes nothing returns nothing
    local timer t = NewTimer()
    local unit u = GetTriggerUnit() //Assuming this is a spell

    call SaveUnitHandle( MyHash, 0, GetHandleId( u ), u )
    call SetTimerData( t, GetHandleId( u ) )
    call TimerStart( t, 10., false, function KillCaster )
endfunction

In this spell (which doesn't have a initializer, thus can't be cast) the caster would die after 10 seconds.
Doesn't make much sence but it's easier to understand this way.
08-10-2009, 02:52 PM#3
thehellman
Thank you for replying.

I just want to point out that i'm looking for a replacement to PolledWait. I understand the NewTimer method, but that would require creating two functions for everything, even simple things such as spells that deal damage to the unit after 2 seconds.

I also have a question about this line:

call SetTimerData( t, GetHandleId( u ) )

What's the point of it? Couldn't you just do (in the first function)

call SaveUnitHandle( MyHash, GetHandleId( t ), 0 , u )

Then in the timer function:

local timer t = GetExpiredTimer()
call KillUnit( LoadSavedHandle( MyHash, GetHandleId(t), 0 ) ) )
08-10-2009, 06:26 PM#4
Cheezeman
Well, if you're looking for a (not entirely, but close to) bugfree way to do stuff, use timers.
If you don't, well, keep using polledwait or triggersleepaction (I don't recommend any of them).
Anyway I did that snippet in like 2 minutes, so yes you may do it your way (silly me)
08-10-2009, 06:58 PM#5
Rising_Dusk
Quote:
Originally Posted by thehellman
I just want to point out that i'm looking for a replacement to PolledWait. I understand the NewTimer method, but that would require creating two functions for everything, even simple things such as spells that deal damage to the unit after 2 seconds.
Yes, and because PolledWait, TriggerSleepAction, and PolledWait2 suck so hard, creating 2 functions for all of your timed actions is a far cleaner and more accurate solution.
08-10-2009, 08:08 PM#6
thehellman
Alright I'll trust you Rising_Dusk, but I do have a question that. What's the GetTimerData function for?

Btw Rising_Dusk when playing AotZ as the samurai, I used his ult, the one where he lunges forward and he infinitely was paused (even after death I was still paused). I'm not exactly sure the cause of it, but a similar thing has happened to a hero spell in my map. Did you ever manage to fix that bug or find it's source?
08-10-2009, 08:38 PM#7
Rising_Dusk
Quote:
Originally Posted by thehellman
What's the GetTimerData function for?
So you can attach an integer (or struct) to the timer so you can associate data to it. This lets you transfer variables between the function calls, basically.
Quote:
Originally Posted by thehellman
Did you ever manage to fix that bug or find it's source?
I did, but I'm hella lazy with AotZ. I am surprised I got off my ass to fix it for the 1.24 patch at all. (Even though it still crashes because of some mysterious bug crap)
08-11-2009, 03:07 PM#8
thehellman
Quote:
Originally Posted by Rising_Dusk
So you can attach an integer (or struct) to the timer so you can associate data to it. This lets you transfer variables between the function calls, basically.

I did, but I'm hella lazy with AotZ. I am surprised I got off my ass to fix it for the 1.24 patch at all. (Even though it still crashes because of some mysterious bug crap)

How did you fix it? I'm having the same problem with my hero.
08-16-2009, 12:27 AM#9
thehellman
Bump for answer?