• 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] Endless Loop -- why?

Status
Not open for further replies.

Rui

Rui

Level 41
Joined
Jan 7, 2005
Messages
7,550
Hi. I have a script that has been giving me trouble.
I'm trying to reconstruct a thing from the RoC Human Campaign, mission "The Culling" (the one where you have to slay the Zombies).
However, I'm using a loop for it, which apparently doesn't want to work. Well, it does, but it doesn't stop, so it blasts the whole thing with units.

Can you find what's wrong with it?
JASS:
function Trig_Plague_Function001 takes nothing returns nothing
  local location ploc = GetUnitLoc(GetEnumUnit())
  local unit dummy = CreateUnitAtLoc(Player(12), 'e000', ploc, 270)
    call IssueTargetOrder(dummy, "darkconversion", GetEnumUnit())
    call UnitApplyTimedLife(dummy, 'BTLF', 3)
  call RemoveLocation(ploc)
  call TriggerSleepAction(1)
  set ploc=null
  set dummy=null
endfunction

function Trig_Plague_Conditions takes nothing returns boolean
  return (IsUnitType(GetDyingUnit(), UNIT_TYPE_STRUCTURE))
endfunction

function Trig_Plague_Actions takes nothing returns nothing
  local rect temprct = Rect(GetUnitX(GetDyingUnit())-200, GetUnitY(GetDyingUnit())-200, GetUnitX(GetDyingUnit())+200, GetUnitY(GetDyingUnit())+200)
  local location l
  local integer repeat = 0
  local unit ibu
  local group peasants=CreateGroup()
  local player toplayer
    if (GetOwningPlayer(GetKillingUnit())==Player(6)) then
     set toplayer = Player(6)
    else
     set toplayer = Player(12)
    endif
//start
  loop 
   exitwhen repeat==GetRandomInt(3,4)
     set l=Location(GetRandomReal(GetRectMinX(temprct), GetRectMaxX(temprct)), GetRandomReal(GetRectMinY(temprct), GetRectMaxY(temprct)))
     set ibu = CreateUnitAtLoc(toplayer, 'nvl2', l, GetRandomReal(0,360))
     call RemoveLocation(l)
     set repeat=(repeat+1)
  endloop
   set l = GetUnitLoc(ibu)
   call GroupEnumUnitsInRangeOfLoc(peasants, l, 250, null)
   call ForGroup(peasants, function Trig_Plague_Function001)
      call TriggerSleepAction(3)
   call DestroyGroup(peasants)
   call RemoveRect(temprct)
   call RemoveLocation(l)
  set temprct = null
  set l = null
  set ibu = null
  set repeat = 0
  set peasants = null
  set toplayer = null
endfunction
//==============================================
function InitTrig_Plague takes nothing returns nothing
 set gg_trg_Plague=CreateTrigger()
 call TriggerRegisterPlayerUnitEvent(gg_trg_Plague, Player(15), EVENT_PLAYER_UNIT_DEATH, null)
 call TriggerAddCondition(gg_trg_Plague, Condition(function Trig_Plague_Conditions))
 call TriggerAddAction(gg_trg_Plagued_Houses, function Trig_Plague_Actions)
endfunction
 

Rui

Rui

Level 41
Joined
Jan 7, 2005
Messages
7,550
Makes sense. The script actually worked twice and then caused an endless loop, so that should be it.
I'll try it and I'll tell the result after testing. Thanks for trying to help ;)

EDIT: It did work. Thanks for the help!
 
Last edited:
Status
Not open for further replies.
Top