HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Help: Creating Looping Triggers

01-15-2007, 04:04 PM#1
StockBreak
Hi, I have a question for you all:
I have many skills and abilities which create triggers that must loop (for example an ability that, when casted, moves the hero every 0.05 seconds).
To do such things I use the Create Trigger function, storing in the gamecache the caster and other useful variables and restoring them every time the newly created trigger fires (in example, every 0.05 seconds).
This method works quite well, but it's very time consuming to write (because I have to save every single needed variable for the looping trigger and sometimes there are more than 15 variables) and I suspect that it causes lag sometimes. Do you have any suggestion? What do you use to make such abilities (for example a projectile that moves until it strikes the first ability)? Thanks.
01-15-2007, 04:11 PM#2
wyrmlord
Use timers.
Collapse JASS:
function TimerCallback takes nothing returns nothing
//do actions here
endfunction

function SpellStart takes whatever returns whatever
 local timer t = CreateTimer()
//Store some values in gamecache or whatever
    call TimerStart(t, rate, true, function TimerCallback)
endfunction
01-15-2007, 04:20 PM#3
grim001
First of all there's no need to create a repeating trigger. You can use a repeating timer with a callback instead.

i.e. call TimerStart(yourtimer, frequency, true, function yourfunction)

where true represents the true/false boolean as to whether the timer repeats.

This alone won't make much of a difference. Assuming you use the Local Handle Variables system, nothing is going to save you from lag. It's pretty much obsolete by now compared to more modern methods such as tables and arrays (using CSCache) and structs (using WEHelper or Grimoire).

A large portion of a local handle var's execution time is the H2I(I2S()) call. Tables work by simply keeping track of the H2I(I2S()) of a handle, for example the periodic timer, so that it only needs to be found once per callback rather than once per variable. Even speedier are dynamic arrays, which allocate a portion of global variable arrays to store whatever you want, although they are not the most practical solution for spells since you must refer to every variable as an integer (gets tedious keeping track of them). They are however perfect for lists since you can simply iterate through the integers.

The best solution right now are structs. They are the fastest and easiest way to store information for a spell; you basically create a custom data structure and name its variables whatever you like. They are almost as fast as storing everything in global variables. In fact that is what it does, although it's all behind-the-scenes. I suggest you look up the Grimoire thread, download it and get used to taking advantage of the awesome features it enables.
01-15-2007, 04:26 PM#4
StockBreak
Quote:
Originally Posted by wyrmlord
Use timers.
Collapse JASS:
function TimerCallback takes nothing returns nothing
//do actions here
endfunction

function SpellStart takes whatever returns whatever
 local timer t = CreateTimer()
//Store some values in gamecache or whatever
    call TimerStart(t, rate, true, function TimerCallback)
endfunction
Yes, this is exactly the method that I normally use for my spells, but are there any other ways?
For example if you want to move a unit to a certain location, how do you handle with the x and y variables? I usually divide the final distance on some "steps": for example if the distance is 1000, I'll make 25 "steps" each of 40 distance to make the movement as smooth as possible.
Then I'll move the unit by 40 every time the trigger fires.
I have also a counter initialized to 0 (stored and increased every time) that, when it reaches 25, will stop the loop.
Do you use a counter too or you simply move the unit to the location; and if you don't use the counter, how do you check the arrival?
Thanks.