| 08-24-2008, 02:47 PM | #1 |
Does this work? Normally, with structs, I've seen and used the method where the global has a constant interval and will only be started if the struct array count is equal to zero (same with pausing). I want to use at least 10 different intervals for one of my spell, but not really the 10 timers that it would require. |
| 08-24-2008, 05:10 PM | #2 |
If you don't make clear what you want, we cannot answer your question. Yes, global timers can run at different intervals, although obviously one timer cannot run at multiple intervals at the same time. |
| 08-24-2008, 05:25 PM | #3 |
| 08-24-2008, 11:18 PM | #4 |
What I'm planning to do is drag in units in a 750 aoe to a certain point in 1 second. Because these units will be located at varying coordinates, the distance = rate * time formula will change for each individual unit. Each unit must reach the target area in the same amount of time, 1 second. Lets say I want a particular unit to move 10 units per interval and it is 500 units away. Therefore, it will take 50 intervals per second, so the timer interval is 1 / 50. If the unit is 700 units away, its a different formula. Finding the right instance of a struct isn't really an issue. But now that I think of it I can probably make the interval constant and the distance per interval variable... that way some units will look choppier but 1 timer can still do it with a constant interval... The intervals will definitely be .04 or smaller than that Vex. |
| 08-26-2008, 05:59 AM | #5 |
No, you still only need one timer with an interval of, say, 0.04. I'll explain:
That formula works because in your case T and I are going to be constant. |
| 08-27-2008, 01:28 AM | #6 | |
Quote:
Thats what I meant Pyro, I've already chosen .04 to be the interval, the T and I are constant and the D differs for each unit :P P.S. thank you for the offset part of the equation, that will help me a lot with movement, I always had to extend my calculations to figure that out. I also appreciate the examples :D |
| 08-27-2008, 04:01 AM | #7 |
Oh, wow, lulz. I misread your post and I thought you said you couldn't think of how to do that. Whoooops. |
| 08-29-2008, 03:34 AM | #8 |
I have another question concerning timers / tracking struct instances. Is it better to track the instance number using gamecache or through a global struct array? As in: JASS:globals struct array struct_Ar integer struct_total=0 endglobals function ReturnInstance takes timer t returns structname local integer i=0 loop exitwhen i>=struct_total if t==struct_Ar[i].timer then return struct_Ar[i] endif endloop return 0 endfunction That is my current method of detecting struct instances. Instead I could use gamecache natives to track the instance (as in Set/GetCSData or timer utils). I've heard its worse to use globals, but I wanted someone else's opinion |
| 08-29-2008, 12:49 PM | #9 |
I can't think of a way to use gamecache for that, please ellaborate. |
| 08-29-2008, 03:12 PM | #10 |
Let's say in a spell trigger your action func runs when your unit casts spell: JASS:function SpellEffect takes nothing returns nothing local struct s=s.create(GetTriggerUnit()) call StoreInteger(cache, I2S(H2I(s.timer)), "instance", s) // s.timer assigned in create method call TimerStart(s.timer, INTERVAl, true, function Callback) endfunction JASS:function Callback takes nothing returns nothing local struct s=GetStoredInteger(cache, I2S(H2I(GetExpiredTimer())), "instance") endfunction |
| 08-29-2008, 03:21 PM | #11 |
If you use a proper timer system like TimerUtils you can just use SetTimerData/GetTimerData to accomplish that. |
| 08-29-2008, 03:22 PM | #12 | |
Quote:
Neither. There are links in the third post of this thread, take a look at them. Both methods you mentioned are terrible, one has O(n) time complexity which means it is not too good for multi instance, the other one requires a gamecache, though the speed doesn't matter matter that much , gamecache can get very heavy as a requirement, and it makes the code look very ugly. Also, if you had many instances of that timer it would be very slow. |
| 08-29-2008, 07:31 PM | #13 |
Alrighty, I think I'll try red timerUtils, since I doubt that in my testmap it will take more than the required limit (if it does I'll use blue). Out of curiosity, what is O(n) time complexity? Also could someone please change the name of my OLY pastebin thread? It is currently [OLY] Doom Nova I'd just like it to be [OLY] Zerzax. EDIT: Thanks for changing it. I have a new question, is SetUnitUserData a good way to associate struct instances with a unit? I realized that a. there isn't a native (that I know of) that flushes this value and b. if there are multiple spells working on a unit that setting this value could conflict easily with other values set to the unit. |
