• 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.

Question about a looping trigger

Status
Not open for further replies.
Level 10
Joined
Dec 15, 2012
Messages
650
Here's my trigger
  • Corpse Continues Decay
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Peasant
    • Actions
      • For each (Integer LoopInteger) from 1 to Int_UnitAfterDead, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Triggering unit) Equal to Suspended_Corpse[LoopInteger]
            • Then - Actions
              • Set TempInteger = (Integer A)
              • Trigger - Run Remove DummyItems <gen> (checking conditions)
              • Set LoopInteger = (Int_UnitAfterDead - 1)
            • Else - Actions
JASS:
function Trig_ABCD_Conditions takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetTriggerUnit()) == 'hpea' ) ) then
        return false
    endif
    return true
endfunction

function Trig_ABCD_Func002Func001C takes nothing returns boolean
    if ( not ( GetTriggerUnit() == udg_Suspended_Corpse[udg_LoopInteger] ) ) then
        return false
    endif
    return true
endfunction

function Trig_ABCD_Actions takes nothing returns nothing
    set udg_LoopInteger = 1
    loop
        exitwhen udg_LoopInteger > udg_Int_UnitAfterDead
        if ( Trig_ABCD_Func002Func001C() ) then
            set udg_TempInteger = GetForLoopIndexA()
            call ConditionalTriggerExecute( gg_trg_Remove_DummyItems )
            set udg_LoopInteger = ( udg_Int_UnitAfterDead - 1 )
        else
        endif
        set udg_LoopInteger = udg_LoopInteger + 1
    endloop
endfunction

//===========================================================================
function InitTrig_ABCD takes nothing returns nothing
    set gg_trg_ABCD = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_ABCD, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_ABCD, Condition( function Trig_ABCD_Conditions ) )
    call TriggerAddAction( gg_trg_ABCD, function Trig_ABCD_Actions )
endfunction
Simple questions :
1.The loop will end when I set LoopInteger = (Int_UnitAfterDead - 1) right ?
2.Will the GUI work as Jass ?


Extra question :
What is the difference of vJass and Jass ?
:ogre_hurrhurr:[highlight]Thanks for replying[/code]:ogre_hurrhurr:
 
Level 10
Joined
Dec 15, 2012
Messages
650
You should not use Integer A since you are not using that in the loop. Neihter the gui or jass will work correctly.

The difference between jass and vjass is that vjass introduces some new coding methods. You can check them here: http://www.wc3c.net/vexorian/jasshelpermanual.html

vjass gets compiled into jass when the map is saved.
Thanks, Maker.
Integer A is my mistake :vw_unimpressed:
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
1.The loop will end when I set LoopInteger = (Int_UnitAfterDead - 1) right ?
The condition for the loop to stop is: LoopInteger > Int_UnitAfterDead
Let's say Int_UnitAfterDead is 5

So, LoopInteger(4) > Int_UnitAfterDead(5)

If you do this, there will be one leaking loop.
You should just set it equal to.
LoopInteger = Int_UnitAfterDead

Set this value just before the udg_LoopInteger = udg_LoopInteger + 1

2.Will the GUI work as Jass ?
Use Custom script.
 
Level 10
Joined
Dec 15, 2012
Messages
650
The condition for the loop to stop is: LoopInteger > Int_UnitAfterDead
Let's say Int_UnitAfterDead is 5

So, LoopInteger(4) > Int_UnitAfterDead(5)

If you do this, there will be one leaking loop.
You should just set it equal to.
LoopInteger = Int_UnitAfterDead

Set this value just before the udg_LoopInteger = udg_LoopInteger + 1
? But I saw the action, set udg_LoopInteger = udg_LoopInteger + 1 so it should be no problem.
JASS:
    loop
        exitwhen udg_LoopInteger > udg_Int_UnitAfterDead
        if ( Trig_Corpse_Continues_Decay_Copy_Func002Func001C() ) then
            set udg_TempInteger = udg_LoopInteger
            call ConditionalTriggerExecute( gg_trg_Remove_DummyItems )
            set udg_LoopInteger = ( udg_Int_UnitAfterDead - 1 )
        else
        endif
        set udg_LoopInteger = udg_LoopInteger + 1
    endloop

Will this work ?
  • Corpse Continues Decay
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Peasant
    • Actions
      • For each (Integer LoopInteger) from 1 to Int_UnitAfterDead, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Triggering unit) Equal to Suspended_Corpse[LoopInteger]
            • Then - Actions
              • Set TempInteger = LoopInteger
              • Trigger - Run Remove DummyItems <gen> (checking conditions)
              • Set LoopInteger = (Int_UnitAfterDead - 1)
            • Else - Actions
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
Let's take a look;
LoopInteger = Int_UnitAfterDead - 1

Which means if Int_UnitAfterDead is 5, then LoopInteger is 4.
After that, LoopInteger = LoopInteger + 1
So LoopInteger = 5 now.

The next check is this; 5 > 5 - FALSE
Therefore, the loop will continue once more.

IF we set without the subtraction, here's it would become;
LoopInteger = Int_UnitAfterDead

Which means if Int_UnitAfterDead is 5, then LoopInteger is 5.
After that, LoopInteger = LoopInteger + 1
So LoopInteger = 6 now.

Next check would be: 6 > 5 - TRUE
Therefore, exit loop.
 
Level 10
Joined
Dec 15, 2012
Messages
650
Let's take a look;
LoopInteger = Int_UnitAfterDead - 1

Which means if Int_UnitAfterDead is 5, then LoopInteger is 4.
After that, LoopInteger = LoopInteger + 1
So LoopInteger = 5 now.

The next check is this; 5 > 5 - FALSE
Therefore, the loop will continue once more.

IF we set without the subtraction, here's it would become;
LoopInteger = Int_UnitAfterDead

Which means if Int_UnitAfterDead is 5, then LoopInteger is 5.
After that, LoopInteger = LoopInteger + 1
So LoopInteger = 6 now.

Next check would be: 6 > 5 - TRUE
Therefore, exit loop.
Thanks ! Your explanation is very clearly :thumbs_up:
 
Status
Not open for further replies.
Top