HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Wait replacement?

03-25-2007, 04:30 PM#1
darkwulfv
Since using timers w/ callbacks refuses to work for me (same with groups w/ callbacks), I thought that perhaps something like this might work.

Collapse JASS:
  local timer t = CreateTimer()
    call TimerStart(t, 2.00, null)
   loop
   exitwhen TimerGetRemaining(t) == 0
   endloop
  // rest of actions

It seems kinda inneficient... but if nothing else wants to work, this might have to do it for any time I can't use a PolledWait() native. (Times under... what was it? .21?) Thanks for your input, and if anyone has a different solution, let me know. And for recurring timers, I'd just have to put the loop inside a loop... or something.
03-25-2007, 07:37 PM#2
blu_da_noob
Or you could just fix your problem with timers/groups. It's not like WC3 looks at who made the map and decides they will spontaneously fail because you made it. You must be doing something wrong, so rather let people help you fix that.
03-25-2007, 07:42 PM#3
Captain Griffen
Your one there would loop infinite and the thread would die. You need a TriggerSleepAction. What you'd then have is basically the PolledWait.

Only accurate way is with timers.
03-25-2007, 09:59 PM#4
darkwulfv
Quote:
Only accurate way is with timers.

Fully aware, but I'm doing something wrong when I work with timers + Callback functions.

Quote:
Or you could just fix your problem with timers/groups. It's not like WC3 looks at who made the map and decides they will spontaneously fail because you made it. You must be doing something wrong, so rather let people help you fix that.

lawl @ the wc3 failure statement. And I didn't post any of the triggers causing me trouble because... Well, I didn't want to seem like a bother, because they seemed like such stupid mistakes and not worth other's time. But if I come across the problem again (which I probably will), I'll post and see if anyone can help.
03-25-2007, 10:24 PM#5
Vexorian
what exactly makes you think that monster you wrote would work?
03-25-2007, 10:56 PM#6
darkwulfv
What? The script in the first post? No idea. Just seemed logical. The trigger loops until the timer hits zero, then moves on. I don't know enough about JASS to know about thread crashes, TriggerSleepAction, etc. etc. etc.
03-25-2007, 11:08 PM#7
Vexorian
Thing is that while you are executin Jass code that doesn't sleep, timers don't advance.
03-26-2007, 12:31 AM#8
darkwulfv
...Still confused, but I'll nod my head and pretend that I'm understanding what you said.

So... TriggerSleepAction does what now?
03-26-2007, 12:53 AM#9
Rising_Dusk
Think of a trigger as a squirrel.
Now think of TriggerSleepAction as a tranquilizer dart that lasts X seconds where X is the time you supply the function (Or how concentrated your tranq is).

Now shoot the trigger with the TSA dart.
You can figure out the rest.
03-26-2007, 12:58 AM#10
darkwulfv
Maybe im just slow today, but that didn't make a whole lotta sense. So basically TSA makes a function... work? Or something?
03-26-2007, 12:59 AM#11
Ammorth
Quote:
Originally Posted by Vexorian
Thing is that while you are executin Jass code that doesn't sleep, timers don't advance.

And he means that functions without a sleep will not pass time. So if you run a huge code without waits that takes your computer 2 seconds to process, the timers in the game will not decrease, until that code is processed. And then they will only decrease by their smallest increment, like the lag from the code never existed.

He was refering to:
Collapse JASS:
  local timer t = CreateTimer()
    call TimerStart(t, 2.00, null)
   loop
   exitwhen TimerGetRemaining(t) == 0
   endloop
where you have no waits, yet are waiting for a timer to finish. The code will continue to process, and hit an infinite loop, because it is looping without allowing the timers to decrease to exit the loop.

Edit: TriggerSleepAction pauses the trigger execution for x number of seconds to allow other functions, timers and what-not to process.

Only one function is processed at a time. When it ends, the next one processes. If one function is constantly processing without a wait, other functions cannot process, nor can timers advance. When a wait is added, the function pauses and then gets back in line once the wait is finished, to allow other functions to process.

Dig?
03-26-2007, 01:02 AM#12
Rising_Dusk
When you shoot a f*cking squirrel with a tranquilizer dart it GOES TO SLEEP.
It doesn't WORK at all, it just falls over and chills until the shit wears off.

TriggerSleepAction puts a thread to sleep for the duration you specify (Be forewarned it is not accurate for tiny intervals).
That's it; when the TSA ends, the thread picks up right where it left off.
That easy.
03-26-2007, 01:05 AM#13
darkwulfv
EDIT: Ok ok ok. So, when the particular thread (function?) is asleep, it allows for other threads (functions?) to process their coding so that it will work when called? If that's right, where's the best place/time to put TSA's?
03-26-2007, 01:11 AM#14
Ammorth
before a thread limit :p When the thread limit is about to occur depends on how many and what type of functions are called.
03-26-2007, 01:25 AM#15
darkwulfv
Do PolledWaits use TSA? If so, then I think I'm ok to go. I use PolledWaits often enough. But what is the thread limit?