• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Timed Loop?

Status
Not open for further replies.
Level 3
Joined
Dec 27, 2008
Messages
56
I need a loop that loops every 0.01 sec. Not that:
JASS:
loop
//Actions
 call PolledWait(0.01)
 exitwhen Condition==true
endloop
A loop for example dor that:
JASS:
loop
//Actions
 call PolledWait(0.01)
 call SetUnitFlyHeight(Unit,GetUnitFlyHeight(Unit)+1,100)
 exitwhen Condition==true
endloop
But that doesn't work...
Does anybody know a loop for that?
 
Level 14
Joined
Nov 18, 2007
Messages
816
no. An event requires some trigger behind it to execute code. A timer executes exactly one function when it expires. And a timer is much cleaner when it comes to memory leaks, code safety, and readability of resulting code.
 
Level 3
Joined
Dec 27, 2008
Messages
56
Maybe you can help me with this:
JASS:
function Bullet takes integer BulletType,unit Bulleter,real Speed,real Angle,real MaxDist,real Radius,integer Number,real x1,real y1,real x2,real y2,real x3,real y3,real x4,real y4 returns nothing
 local location BulleterPos=GetUnitLoc(Bulleter)
 local unit array Bullets
 local location array BulletShotPos
 local integer l=0
 
 set BulletShotPos[1]=OffsetLocation(BulleterPos,x1,y1)
 set BulletShotPos[2]=OffsetLocation(BulleterPos,x2,y2)
 set BulletShotPos[3]=OffsetLocation(BulleterPos,x3,y3) 
 set BulletShotPos[4]=OffsetLocation(BulleterPos,x4,y4) 
 
 set Bullets[1]=CreateUnitAtLoc(Player(12),BulletType,BulletShotPos[1],Angle)
 call GroupAddUnit(udg_MovingBullets,Bullets[1])
 call StoreReal(udg_Cache,"Speed",I2S(H2I(Bullets[1])),Speed)
 call StoreReal(udg_Cache,"MaxDist",I2S(H2I(Bullets[1])),MaxDist)
 call StoreReal(udg_Cache,"Radius",I2S(H2I(Bullets[1])),Radius)
 call StoreReal(udg_Cache,"DistLeft",I2S(H2I(Bullets[1])),0)

 if Number>=2 then
  set Bullets[2]=CreateUnitAtLoc(Player(12),BulletType,BulletShotPos[2],Angle)
  call GroupAddUnit(udg_MovingBullets,Bullets[2])
  call StoreReal(udg_Cache,"Speed",I2S(H2I(Bullets[2])),Speed)
  call StoreReal(udg_Cache,"MaxDist",I2S(H2I(Bullets[2])),MaxDist)
  call StoreReal(udg_Cache,"Radius",I2S(H2I(Bullets[2])),Radius)
  call StoreReal(udg_Cache,"DistLeft",I2S(H2I(Bullets[2])),0)
 endif
 
 if Number>=3 then
  set Bullets[3]=CreateUnitAtLoc(Player(12),BulletType,BulletShotPos[3],Angle)
  call GroupAddUnit(udg_MovingBullets,Bullets[3])
  call StoreReal(udg_Cache,"Speed",I2S(H2I(Bullets[3])),Speed)
  call StoreReal(udg_Cache,"MaxDist",I2S(H2I(Bullets[3])),MaxDist)
  call StoreReal(udg_Cache,"Radius",I2S(H2I(Bullets[3])),Radius)
  call StoreReal(udg_Cache,"DistLeft",I2S(H2I(Bullets[3])),0)
 endif
 
 if Number>=4 then
  set Bullets[4]=CreateUnitAtLoc(Player(12),BulletType,BulletShotPos[4],Angle)
  call GroupAddUnit(udg_MovingBullets,Bullets[4])
  call StoreReal(udg_Cache,"Speed",I2S(H2I(Bullets[4])),Speed)
  call StoreReal(udg_Cache,"MaxDist",I2S(H2I(Bullets[4])),MaxDist)
  call StoreReal(udg_Cache,"Radius",I2S(H2I(Bullets[4])),Radius)
  call StoreReal(udg_Cache,"DistLeft",I2S(H2I(Bullets[4])),0)
 endif

 loop
  exitwhen l==5
  call RemoveLocation(BulletShotPos[l])
  set Bullets[l]=null
  set l=l+1
 endloop
 
 call RemoveLocation(BulleterPos)
 set Bulleter=null
 
endfunction

JASS:
function MoveBullets takes nothing returns nothing
 local group AllBullets=udg_MovingBullets
 local group BulletsLeft=null
 local unit First=null
 local location Loc=null
 local real Face
 
 loop
  set First=FirstOfGroup(AllBullets)
  exitwhen First==null
  set Loc=GetUnitLoc(FirstOfGroup(AllBullets))
  set Face=GetUnitFacing(First)
  call StoreReal(udg_Cache,"DistLeft",I2S(H2I(First)),GetStoredReal(udg_Cache,"DistLeft",I2S(H2I(First)))+1)
  
  if GetStoredReal(udg_Cache,"DistLeft",I2S(H2I(First)))==GetStoredReal(udg_Cache,"MaxDist",I2S(H2I(First))) then
   call RemoveUnit(First)
   set First=null
  endif 
  
  call SetUnitPositionLoc(First,PolarProjectionBJ(Loc,GetStoredReal(udg_Cache,"Speed",I2S(H2I(First))),Face))
 endloop
 
 set AllBullets=null
 set BulletsLeft=null
 set First=null
 call RemoveLocation(Loc)
endfunction 

//===========================================================================
function InitTrig_Bullets takes nothing returns nothing
    set gg_trg_Bullets = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Bullets, 0.01 )
    call TriggerAddAction( gg_trg_Bullets, function MoveBullets )
endfunction

I activated it with this:

JASS:
function Trig_dsf_Actions takes nothing returns nothing
 call Bullet('BU01',gg_unit_XWIN_0007,2,GetUnitFacing(gg_unit_XWIN_0007),1500,50,1,0,0,0,0,0,0,0,0)
endfunction
// integer BulletType,unit Bulleter,real Speed,real Angle,real MaxDist,real Radius,integer Number,real x1,real y1,real x2,real y2,real x3,real y3,real x4,real y4 returns nothing
//===========================================================================
function InitTrig_dsf takes nothing returns nothing
    set gg_trg_dsf = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_dsf, Player(0), "-go", true )
    call TriggerAddAction( gg_trg_dsf, function Trig_dsf_Actions )
endfunction

I tested my bulleting system with an Gryphon Rider
JASS:
'BU01'
.

But nothing happened.. Why?
I used the periodic timer.
When i remove the
JASS:
call RemoveUnit(First)
WC3 fucks down.
 
Last edited:
Level 14
Joined
Nov 18, 2007
Messages
816
is udg_MovingBullets initialized?
Do you actually understand what youre doing there? Do you know units DO get removed when you call RemoveUnit() on them, and nothing can bring them back?
Why do you even use a group for looping through a finite, known number of units, and why dont you use an array of units?
Why dont you use real coordinates?
 
Level 3
Joined
Dec 27, 2008
Messages
56
I know what i do there but i don't know hy Wc3 fucks down when i remove call RemoveUnit(First).
The bullet should be removed, yes.
 
Status
Not open for further replies.
Top