• 🏆 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!

Problem with loop

Status
Not open for further replies.
Level 2
Joined
Jun 26, 2007
Messages
14
JASS:
function Trig_Set_SnowballRect_Actions takes nothing returns nothing
local integer i=1
    set udg_SnowballRect[1] = gg_rct_S1
    set udg_SnowballRect[2] = gg_rct_S2
    set udg_SnowballRect[3] = gg_rct_S3
    set udg_SnowballRect[4] = gg_rct_S4
    set udg_SnowballRect[5] = gg_rct_S5
    set udg_SnowballRect[6] = gg_rct_S6
    set udg_SnowballRect[7] = gg_rct_S7
    set udg_SnowballRect[8] = gg_rct_S8
    set udg_SnowballRect[9] = gg_rct_S9
    set udg_SnowballRect[10] = gg_rct_S10
    set udg_SnowballRect[11] = gg_rct_S11
    set udg_SnowballRect[12] = gg_rct_S12
    set udg_SnowballRect[13] = gg_rct_S13
    set udg_SnowballRect[14] = gg_rct_S14
    set udg_SnowballRect[15] = gg_rct_S15
    set udg_SnowballRect[16] = gg_rct_S16
    set udg_SnowballRect[17] = gg_rct_S17
    set udg_SnowballRect[18] = gg_rct_S18
    set udg_SnowballRect[19] = gg_rct_S19
    set udg_SnowballRect[20] = gg_rct_S20
    set udg_SnowballRect[21] = gg_rct_S21
    set udg_SnowballRect[22] = gg_rct_S22
    set udg_SnowballRect[23] = gg_rct_S23
    set udg_SnowballRect[24] = gg_rct_S24
    loop
        exitwhen i>24
        call TriggerRegisterEnterRectSimple( gg_trg_SnowballSend, udg_SnowballRect[i] )
        set i=i+1
    endloop
endfunction

function InitTrig_Set_SnowballRect takes nothing returns nothing
    set gg_trg_Set_SnowballRect = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Set_SnowballRect, function Trig_Set_SnowballRect_Actions )
endfunction

JASS:
function Trig_SnowballSend_Conditions takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetTriggerUnit()) == 'Snbl' ) ) then
        return false
    endif
    return true
endfunction

function Trig_SnowballSend_Actions takes nothing returns nothing
local integer i=1
local integer r=0
local unit u = GetTriggerUnit()
local location p
    if ( RectContainsUnit(udg_SnowballRect[24], u ) == true ) then
        call DisplayTextToPlayer(Player(0), 0, 0, "Reached last region of " + I2S(i))
        call KillUnit(u)
    else
        loop
            exitwhen i>23
            if ( RectContainsUnit(udg_SnowballRect[i], u ) == true ) then
                set r=i + 1
                call DisplayTextToPlayer(Player(0), 0, 0, "In region " + I2S(i)) 
                exitwhen true
            else
                call DisplayTextToPlayer(Player(0), 0, 0, "Not in region " + I2S(i))
                set i=i+1
            endif
        endloop
        call DisplayTextToPlayer(Player(0), 0, 0, "Going to region " + I2S(r))
        set p = (GetRectCenter(udg_SnowballRect[(r)]))
        call IssuePointOrderLocBJ(u, "move", p)
    endif
endfunction


function InitTrig_SnowballSend takes nothing returns nothing
    set gg_trg_SnowballSend = CreateTrigger(  )
    call TriggerAddCondition( gg_trg_SnowballSend, Condition( function Trig_SnowballSend_Conditions ) )
    call TriggerAddAction( gg_trg_SnowballSend, function Trig_SnowballSend_Actions )
endfunction

So between these two triggers and the regions(1-24) that I've set up, what should happen is that when a unit enters the first region, hes sent through all of them and gets killed at the last one.

Well, when i test it, the snowball gets to the 7th region he turns around back to the 6th, which sends him in a loop.

I added a couple message displays to help the debugging process:

As you can see in the 2nd and 3rd screenshot, the trigger doesnt recognize that the unit is in region 7 and goes till the end of the loop.


If you wanna look at the map just ask and I'll PM it to you.
 
Level 2
Joined
Jun 26, 2007
Messages
14
I made a few edits to this, and in turn the snowball will go up to the 7th region, and instead of moving from there, he just stays. (Though, my debugging messages still show up the same)

Here's the new code:
JASS:
function Trig_SnowballSend_Conditions takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetTriggerUnit()) == 'Snbl' ) ) then
        return false
    endif
    return true
endfunction

function Trig_SnowballSend_Actions takes nothing returns nothing
local integer i=1
local integer r=0
local unit u = GetTriggerUnit()
local location p
    if ( RectContainsUnit(udg_SnowballRect[24], u ) == true ) then
        call DisplayTextToPlayer(Player(0), 0, 0, "Reached last region of " + I2S(i))
        call KillUnit(u)  
    else
        loop
            exitwhen i>23
            if ( RectContainsUnit(udg_SnowballRect[i], u ) == true ) then
                set r=i
                call DisplayTextToPlayer(Player(0), 0, 0, "In region " + I2S(i))
                call DisplayTextToPlayer(Player(0), 0, 0, "Going to region " + I2S(r + 1))
                set p = (GetRectCenter(udg_SnowballRect[(r + 1)]))
                call IssuePointOrderLocBJ(u, "move", p)
                exitwhen true
            else
                call DisplayTextToPlayer(Player(0), 0, 0, "Not in region " + I2S(i))
                set i=i+1
            endif
        endloop
    endif
call RemoveLocation(p)
endfunction


function InitTrig_SnowballSend takes nothing returns nothing
    set gg_trg_SnowballSend = CreateTrigger(  )
    call TriggerAddCondition( gg_trg_SnowballSend, Condition( function Trig_SnowballSend_Conditions ) )
    call TriggerAddAction( gg_trg_SnowballSend, function Trig_SnowballSend_Actions )
endfunction

More specifically i moved
JASS:
call DisplayTextToPlayer(Player(0), 0, 0, "Going to region " + I2S(r + 1))
set p = (GetRectCenter(udg_SnowballRect[(r + 1)]))
call IssuePointOrderLocBJ(u, "move", p)
into the loop

and moved the addition of 1 to r from
JASS:
set r=i+1
to
JASS:
set p = (GetRectCenter(udg_SnowballRect[(r + 1)]))
 
Use this and tell me what happens.

JASS:
function Trig_SnowballSend_Conditions takes nothing returns boolean
    return GetUnitTypeId(GetTriggerUnit()) == 'Snbl'
endfunction

function Trig_SnowballSend_Actions takes nothing returns nothing
    local integer i=1
    local integer r=0
    local unit u = GetTriggerUnit()
    local location p
    if ( RectContainsUnit(udg_SnowballRect[24], u ) == true ) then
        call DisplayTextToPlayer(Player(0), 0, 0, "Reached last region of " + I2S(i))
        call KillUnit(u)
    else
        loop
            exitwhen i>23
            if ( RectContainsUnit(udg_SnowballRect[i], u ) == true ) then
                set r=i
                call BJDebugMsg("Region " + I2S(r+1) + "'s handle id is " + I2S(GetHandleId(udg_SnowballRect[(r + 1)])))
                set p = (GetRectCenter(udg_SnowballRect[(r + 1)]))
                call IssuePointOrderLocBJ(u, "move", p)
                call RemoveLocation(p)
                set i = 69
            else
                set i=i+1
            endif
        endloop
    endif
    set p = null
    set u = null
endfunction


function InitTrig_SnowballSend takes nothing returns nothing
    set gg_trg_SnowballSend = CreateTrigger(  )
    call TriggerAddCondition( gg_trg_SnowballSend, Condition( function Trig_SnowballSend_Conditions ) )
    call TriggerAddAction( gg_trg_SnowballSend, function Trig_SnowballSend_Actions )
endfunction
 
Status
Not open for further replies.
Top