| 11-13-2006, 04:47 PM | #1 | ||
Hi: I've been browsing this page in order to find information about timers, specifically the function call TimerStart(time, 4, false, null). In all the scripts where I use timers, I always use them in order to control the duration of one spell getting the remain time and storing in a real variable. But now I've found some inconvenients. I'm doing a Jass spell based on Unholy Frenzy, where the unit get an increased attack speed but drains life. With this script I add chain effect and a special behaviour, which links the caster with the target unit, so this unit will look like a pet for the caster. In order to understand better the spell, please check the hidden information:
Well, this code is nice and meets the JESP standard, but the problem is the usage of TriggerSleepAction() function, the minimum value which I can use is 0.1 seconds, in theory it's enough, but when the target unit moves, the chain effect "jumps" and looks ugly. Resuming I heve this questions:
Thanks for your help :) |
| 11-13-2006, 05:12 PM | #2 |
An example of a timer in action -- JASS:function H2I takes handle h returns integer return h return 0 endfunction function I2Timer takes integer i returns timer return i return null endfunction function TimerCallback takes nothing returns nothing local integer i = H2I(GetExpiredTimer()) //Do stuff call DestroyTimer(I2Timer(i)) endfunction function TimerBeginner takes nothing returns nothing local integer i = H2I(CreateTimer()) call TimerStart(I2Timer(i), .033, true, function TimerCallback) endfunction Now that gets the job done. Creates a timer, does stuff once, destroys the timer. No leaks, hooray. However, there really isn't a point to a periodic timer if you don't run it multiple times. Being that I'm at school and don't know exact native arguments offhand, if I make a mistake in the following code let me apologize in advance. JASS:function TimerCallback takes nothing returns nothing local integer i = H2I(GetExpiredTimer()) local real cur = TimerGetElapsed(I2Timer(i)) //Check me on this native! //ninja local real dur = 2.0 //*********************************************************************** //* Math is your friend! * //* dur/iterations = interval Therefore... * //* interval*iterations = maxduration * //* * //* Use these formulae to get what you need time wise. * //*********************************************************************** //Do stuff based on variable cur or whatever if cur >= dur then call PauseTimer(I2Timer(i)) //A call I like to use to be safe call DestroyTimer(I2Timer(i)) endif endfunction function TimerBeginner takes nothing returns nothing local integer i = H2I(CreateTimer()) call TimerStart(I2Timer(i), .033, true, function TimerCallback) endfunction Note I skipped the I2Timer() and H2I() declarations in the just above example. Now assuming everything is right, that timer I just made will run until the elapsed time on it is greater than your maximum duration. Hopefully SOMETHING of what I said here will make sense. So rawr. :D Notably, many people would argue I2Timer() is unnecessary. In my examples, they would be correct. However, once you get more complicated and start attaching handles or some such to the timer, you're going to want to avoid setting timers to null. Because of that, using the H2I()/I2Timer() is one way to keep it clean. |
| 11-13-2006, 05:35 PM | #3 |
I was under the impression TimerGetElapsed returned the time elapsed on each repetition of a repeating timer. That's what I always assumed anyway. Does it 'stockpile' the time for a repeating one? |
| 11-13-2006, 05:56 PM | #4 |
It's worth looking into for sure. I was under that it would return the stockpiled time it's taken. However, if it does not then I'll rewrite the above bits to use a stored integer. I'll have to test it when I get home from work. Notably I use the stored integer method for AotZ, I was just doing it this way because I couldn't remember the exact functions I use. |
| 11-13-2006, 06:00 PM | #5 |
I'll test it now. Nope, doesn't keep a running count. Just gives the time elapsed on that 'iteration' of the timer. |
| 11-13-2006, 06:35 PM | #6 |
This sort of stuff needs some serious documentation. I'll update the post above -- And heck, while I'm at it submit a tutorial. This stuff can be confusing. :/ |
| 11-13-2006, 10:45 PM | #7 |
Wow!!! Thanks for the help Rising and Blu :) I'll do some test, and I'll tell you how they behave. But seriously I think there should be a tutorial about timers, it's something confusing sometimes. |
| 11-14-2006, 12:56 AM | #8 |
Well, I wrote a timer tutorial just tonight to help out with this sort of thing. Check it out, tell me if it helps at all. :P |
