• 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] Multiple events

Status
Not open for further replies.
Level 5
Joined
May 15, 2008
Messages
105
Trigger "LeavingArea" is complexed. It compiles so I paste only the Init function because I want to ask about it.

JASS:
function InitTrig_LeavingArea takes nothing returns nothing

    set gg_trg_LeavingArea = CreateTrigger(  )

    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 107
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        call TriggerRegisterLeaveRectSimple( gg_trg_LeavingArea, udg_Area_Region[GetForLoopIndexA()])
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    call TriggerAddAction( gg_trg_LeavingArea, function Trig_LeavingArea_Actions )

endfunction

Problem:
Trigger doesn't run when one of events occurs. I have used
JASS:
call DisplayTimedTextToForce( bj_FORCE_PLAYER[0], 120.00, [test string] )
to test it. It clearly shows Trig_LeavingArea_Actions is not executed.

Question:
Why it doesn't work/how to fix?
 
Level 5
Joined
May 15, 2008
Messages
105
also if you are going to use jass you should use locals, replace forloopindexa and forloopaindexend with local integer something
Can it cause errors in this case?


gg_trg_Group_Buildings include call TriggerExecute(gg_trg_Group_Buildings_Plus). These two triggers initialise variables. I have removed event from gg_trg_Group_Buildings and added TriggerExecute to the code (pasted below). The trigger is still not working.

JASS:
function InitTrig_LeavingArea takes nothing returns nothing

    set gg_trg_LeavingArea = CreateTrigger(  )
    call TriggerExecute( gg_trg_Group_Buildings )
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 107
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        call TriggerRegisterLeaveRectSimple( gg_trg_LeavingArea, udg_Area_Region[GetForLoopIndexA()])
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    call TriggerAddAction( gg_trg_LeavingArea, function Trig_LeavingArea_Actions )
endfunction
 
Level 5
Joined
May 15, 2008
Messages
105
Not solved. The problem is gg_trg_Group_Buildings (variable initialization) is executed after the loop (DisplayTimedTextToForce displays zeros). How can I fix that?

JASS:
function InitTrig_LeavingArea takes nothing returns nothing
    local integer i = 1
    set gg_trg_LeavingArea = CreateTrigger(  )
    call TriggerExecute( gg_trg_Group_Buildings )
    loop
        exitwhen i > udg_NumberOfTowns
        call TriggerRegisterLeaveRectSimple( gg_trg_LeavingArea, udg_Area_Region[i])
        call DisplayTimedTextToForce( bj_FORCE_PLAYER[0], 120.00, R2S(GetRectCenterX(udg_Area_Region[i])) )
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    call TriggerAddAction( gg_trg_LeavingArea, function Trig_LeavingArea_Actions )
endfunction

NumberOfTowns has a default value = 107.
 
Another issue might be, as gorillabull said, that your rects haven't been defined yet. To fix this, change the code to:
JASS:
function LeavingArea_onStart takes nothing returns nothing
    local integer i = 1
    call DestroyTimer(GetExpiredTimer())
    set gg_trg_LeavingArea = CreateTrigger(  )
    call TriggerExecute( gg_trg_Group_Buildings )
    loop
        exitwhen i > udg_NumberOfTowns
        call TriggerRegisterLeaveRectSimple( gg_trg_LeavingArea, udg_Area_Region[i])
        call DisplayTimedTextToForce( bj_FORCE_PLAYER[0], 120.00, R2S(GetRectCenterX(udg_Area_Region[i])) )
        set i = i + 1 // fixed it as Arhowk said
    endloop
    call TriggerAddAction( gg_trg_LeavingArea, function Trig_LeavingArea_Actions )
endfunction

function InitTrig_LeavingArea takes nothing returns nothing
    call TimerStart(CreateTimer(), 0, false, function LeavingArea_onStart)
endfunction

That way it will wait for the game to start before doing its actions instead of during initialization (where some things might not have been defined yet).
 
Status
Not open for further replies.
Top