HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Why are Waits so Evil and Timers so Good ?

08-18-2008, 05:57 PM#1
Flame_Phoenix
Hi guys I am doing my map, and one of the coders of the team likes using waits some times. I don't like them, but I don't know enough to prove to him they are really evil.

This are the reasons I think Waits are evil, can some one tell me if they are correct or add more reasons about why shouldn't use waits please ? :
1 - waits are not accurate
2 - waits can cause memory corruption due bad use of CPU and thus a game crash
3 - waits diminish code's efficiency greatly because they use an assembly instruction "nop" which means "do nothing on the cycle", thus although the CPU could be working on something else for the machine it is wasting precious cycles in a stupid way
4 - waits can cause threads to crash
5 - waits ca not be used in ForGroup and in Boolexpr
6 - waits produce weird effects if used in filters


Why are waits better:
1 - waits are more efficient than timers ( is this truth !?)
2 - waits are easier to use

Why are timers better:
1 - they are more accurate then waits
2 - they don't do all evil stuff waits do

Can some one help me out this please ?
08-18-2008, 06:06 PM#2
rulerofiron99
It's mainly an issue of accuracy and stability (timers) vs. ease of use. I also doubt that waits are more efficient - even if they are, the difference is marginal, practicaly insignificant.

As an example:
I was making a TD with spawning using waits.
Trigger 1:
Turn on (spawn)
Wait 20
Turn off (spawn)
Spawn:
Time - every 0.75
Unit - Spawn (unit)

Technically, this should always spawn (20)/(0.75), with a slight variation due to logic. However, during one spawning session, I Alt-Tab'd out of warcraft, and on my return I noticed that it spawned less that usual. This is because waits are not as efficient/stable as timers.

If your coder likes to use waits, first look at the trigger he is using it in to determine if it's bad or not. In most cases (spells, advanced triggers, etc), timers are better. However, in simple time intervals (like next round in 30 seconds or such), waits are practically no different from timers.
08-18-2008, 06:08 PM#3
Strilanc
The main advantage of waits is that you keep access to local variables, and don't need to cleanup. The main disadvantage is accuracy and killing ForGroup/conditions/etc.

I think as long as the functions doing waits aren't being called from elsewhere, it's fine. So you can use them in isolation, but functions that other triggers and systems call should never be waiting.

Maybe get him to try Decal? It hides all the timer and attaching stuff behind a function.
http://wc3campaigns.net/showthread.php?t=101403
08-18-2008, 06:45 PM#4
Vexorian
I don't consider waits evil, they are just lame, there is also the detail that their durations get very unpredictable when they are used in quantity and there are many players in the game, or that they really can't use short times. I think timers (without attaching or anything) are more efficient than waits.
08-18-2008, 08:18 PM#5
Themerion
With the help of Deaod, I made some testing to confirm Anitarf's predictions.

Never use waits in multiplayer. The "Waiting for players"-window won't prevent waits from ticking.

In other words, when the player has dropped, all your waits will have gone through 45 seconds (at max).
08-18-2008, 09:36 PM#6
ADOLF
Collapse JASS:
 local timer t=CreateTimer()
 call TimerStart(t, 8192., false, null)
 call TriggerSleepAction(0.)
 call BJDebugMsg("min TriggerSleepAction period - "+R2S(TimerGetElapsed(t)))

hm...

i use only timers)
08-18-2008, 09:44 PM#7
Toadcop
the main feature of sleep is what it does need to be synchronized between players. well it does mess alot with it.
+ sleep in dead trigger = omfg evil =) it does put the last destroyed object to the handle stack. (or does it require 2+ sleeps) but well anyway.
the main reason is what it's unprecise and makes algorithm logic weird.
08-18-2008, 10:22 PM#8
Vexorian
Quote:
Originally Posted by Themerion
With the help of Deaod, I made some testing to confirm Anitarf's pancakes*.

Never use waits in multiplayer. The "Waiting for players"-dialog won't prevent waits from ticking.

In other words, when the player has dropped, all your waits will have gone through 45 seconds (at max).

*predictions. Sorry, I couldn't help myself. IRC-joke. :)
It is not like dialogs are supposed to pause anything in multiplayer, I think they don't even pause the game?
08-18-2008, 10:33 PM#9
Strilanc
Quote:
Originally Posted by Vexorian
It is not like dialogs are supposed to pause anything in multiplayer, I think they don't even pause the game?

He meant the lag screen, not normal dialogs.
08-18-2008, 10:34 PM#10
TKF
I use waits in my map. Is there something wrong with that? Waits is my favorite action.


I only use timer on my demon cage though, cuz i need those spines at perfect height, otherwise I use waits on not so critical spells.
08-18-2008, 10:53 PM#11
TheDamien
Waits are for sissies and GUI users.
08-18-2008, 11:10 PM#12
Themerion
Quote:
Waits are for sissies and GUI users.

Waits shorten code considerably. They also allow for functions to lock the current running thread (as used by Vexorian in the Caster System).

Waits should be for everyone, since they are really nifty.

Waits are for nobody. They are unsafe.
08-18-2008, 11:30 PM#13
Vexorian
Quote:
Originally Posted by Strilanc
He meant the lag screen, not normal dialogs.
How does that work for timers though? I guess PolledWait should work anyway?

Quote:
They also allow for functions to lock the current running thread (as used by Vexorian in the Caster System
I never liked that, the problem is that normal Jass inherits a lot of lame things from GUI, one is that it was easier and even faster to use a single wait rather than a timer + attachment in those times, right now it is the other way around, whoever thought of vJass...
08-18-2008, 11:35 PM#14
Themerion
It's still easier.
08-19-2008, 12:11 AM#15
MaD[Lion]
or u all can try out my crazy macro abuse timing system for the old fashion way of making waits, just now more accurate and same simplicity