• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Need some help with periodic events via timers

Status
Not open for further replies.
Level 1
Joined
May 18, 2011
Messages
2
Sigh, I am trying to make my first MUI spell and ended up with this problem.

I need to run a specific function, every 0.01 second without switching on and off triggers with periodic events (so that I can use local variables). The function that needs to be run is:
JASS:
function Attack takes unit projectile, real CasterX, real CasterY, unit Caster returns nothing

Thus, I tried this:

JASS:
call TimerStart( T, 0.01, true, function Attack( projectile , CasterX , CasterY, GetSpellAbilityUnit() ) )

The error message is " Expected ' ".
I believe the reason that didn't work is because JASS refuses to let me pass parameters to a "function within a function" when such a function is required as a parameter of the original function, since I have a similar line that can't work:

JASS:
call GroupEnumUnitsInRange( targets, GetUnitX(projectile), GetUnitY(projectile), 100, Condition(function IsTargetNotSelf(projectile) ))

...or I may be completely wrong...(new to JASS)
So... any experts willing to help me with these? I really don't want to resort to arrays and hashtables... (they make my brain hurt)
 
Sadly, you have to use hashtables/arrays for that. Hashtables are the most friendly to new JASSers.

When providing an argument for a code input, the function input must not have any arguments.

So this would be valid as a callback for a timer:
function Test takes nothing returns nothing
While this would bring up an error if used as a callback for a timer:
function Test takes unit u returns nothing

For hashtables, there are several things at your disposal. I recommend that you read:
http://www.thehelper.net/forums/showthread.php/162408-How-to-Use-Timers-in-JASS

It will help introduce you to the world of timers and how to implement them in JASS. Good luck, you can respond with any questions if you have any. =)
 
Level 16
Joined
May 1, 2008
Messages
1,605
Moin moin =)

Well, the thread got the mark [vJass].In the thread of the link I miss this, that you need to use a hastable for an own struct timer.

JASS:
// put this in the globals second
private constant hashtable H = InitHashtable

JASS:
// before you use "call TimerStart()" you have to do this:
call SaveInteger(H,GetHandleId(t),0,data)

JASS:
// in the loop then you have to load it:
local integer data = LoadInteger(H,GetHandleId(t),0)

Also I don't think I need to say it, but using 0.01 seconds isn't good, take 0.04 seconds

Greetings and Peace
Dr. Boom
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
Don't run it every .01 seconds.. run it every .03125 seconds. JASS can only execute code 32x a second, so ur just pointlessly queuing up code with this.

For this, you don't want to use a hashtable. If it is a single instance timer, you want to use just single variables. If it is a multi instance timer, then you want to use either a stack, a queue, or a linked list.

If you are destroying instances arbitrarily, you want to use a linked list.

If you aren't destroying instances but the order matters, you want to use a queue.

If the order doesn't really matter, you want to use a stack.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
JASS can only execute code 32x a second, so ur just pointlessly queuing up code with this.

What do you want mean ?

One day i made a camera pan script (camera traveling but the player must be allow to click on units).
And there was a hudge difference between 1/32 and 1/100.

I'm agree 1/32 period is enough for many cases, as here, but not for all.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
it only executes code 32x a second.. the rest is clumped together in the same intervals.

Not sure where this was tested, but it was =P.

SC2 only executes 32x a second too =), and its min time is .03125 for the timers.

How do you know it ?
Coz i'm pretty sure the camera pan was definetely very smooth with 1/100, i mean if i used a higher value, such as 1/32, when the player clicked on a unit it was very noticeable, but almost none with 1/100 (didn't tried a lower value, coz 0.01 was good enough for me)

About sc2 i've read that, but about wc3 i can't believe it, try to increase a global integer in a periodic timer 1/32 and in a periodic timer 1/100, wait few seconds and print both values, you will see a difference.

EDIT : AFAIK the lowest timeout value is 0.001 or 0.0001, don't remember exactly but it's easy to test, a 0 period is the lowest possible ever.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Only way to actually test is via RtC stopwatch.

Hmm i don't understand, so why i have more timer iterations when i use a 1/100 timer than a 1/32 timer ?
Thats doesn't make sense for me.

JASS:
library Test initializer init

   globals
      private integer I = 0
      private integer J = 0
   endglobals

   private function F1 takes nothing returns nothing
      set I = I + 1
   endfunction

   private function F2 takes nothing returns nothing
      set J = J + 1
   endfunction

   private function init takes nothing returns nothing
      call TimerStart(CreateTimer(),0.03125,true,function F1)
      call TimerStart(CreateTimer(),0.01,true,function F2)
      call TriggerSleepAction(3.)
      call BJDebugMsg(" I == " + I2S(I) )
      call BJDebugMsg(" J == " + I2S(J) )
   endfunction

endlibrary
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
I told you that it clumps..

if you have a timer running 96 times a second, it'll run through three times 32x a second.
expire
--->run
--->run
--->run
expire
--->run
--->run
--->run

But anyways, perhaps I am wrong, even though every vet programmer says that wc3 runs max of 32x a second =P.

Oh well, no real way to know unless RtC is fixed
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Hmm, it doesn't explain the pan camera thing, so i believe it's false (or i'm still missing something).
I mean i would see no difference with 1/32 period against 1/96, because pan the camera 3 times each 1/32 or only one time wouldn't make a visual difference.
 
Status
Not open for further replies.
Top