• 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] Arrays/Multiple Events for a Single Function

Status
Not open for further replies.
Level 2
Joined
Nov 5, 2008
Messages
9
So I'm working on an in-depth puzzle/riddle game set up in a labyrinth. I've got the majority of the planning done and am now setting up basic systems and the terrain.

I'm having some difficulties triggering multiple events for a single function. What I want to do is set this trigger and two others like it to deal with opening and closing the different types of gates in my map (there are going to a lot of them), so all I have to do to add more gates is change the max number of gates and set the corresponding destructible and region variables to the correct arrays.

I've managed to get the events working (at least to my knowledge); however, my arrays are not. I can substitute the arrays in the code for a single corresponding variable and it works perfectly, but use the array and nothing happens. The debug code shows execution flowing as intended.


'Custom Script':
JASS:
function InitializeGameConstants takes nothing returns nothing
    // =======
    // GENERAL
    // =======
    set udg_NUM_UNLOCKED_GATES = 1
    set udg_NUM_LOCKED_GATES = 0
    set udg_NUM_MASTER_GATES = 0
    // ========
    // UNLOCKED
    // ========
    // Gates
    set udg_U_Gate[1] = gg_dest_B00A_0000
    set udg_U_Gate[2] = gg_dest_B00F_0007
    set udg_U_Gate[3] = gg_dest_B008_0014
    set udg_U_Gate[4] = gg_dest_B009_0002
    set udg_U_Gate[5] = gg_dest_B009_0011
    // Regions
    set udg_U_Region[1] = gg_rct_U_Gate_01
    // ======
    // LOCKED
    // ======
    // Gates
    set udg_L_Gate[1] = gg_dest_B000_0001
    set udg_L_Gate[2] = gg_dest_B004_0003
    set udg_L_Gate[3] = gg_dest_B003_0008
    set udg_L_Gate[4] = gg_dest_B004_0013
    set udg_L_Gate[5] = gg_dest_B000_0009
    set udg_L_Gate[6] = gg_dest_B006_0010
    // Regions
    // ======
    // MASTER
    // ======
    // Gates
    // Regions
endfunction

Trigger Unlocked Gates:
JASS:
function Trig_Open_Unlocked_Gate_Func001 takes nothing returns boolean
    if ( not ( udg_U_Region[bj_forLoopAIndex] == udg_tempRegion[1] ) ) then
        return false
    endif
    if ( not ( udg_U_gateIsOpen[bj_forLoopAIndex] == false ) ) then
        call DisplayTextToForce( GetPlayersAll(), "Gate already open" )
        return false
    endif
    return true
endfunction

function Trig_Open_Unlocked_Gate_Func002 takes integer i returns nothing
    set udg_U_gateIsOpen[i] = true
    call DisplayTextToForce( GetPlayersAll(), ( "Opening Gate #: " + I2S(i) ) )
    call KillDestructable(udg_U_Gate[i])
    call SetDestructableAnimation(udg_U_Gate[i], "death alternate")
    call TriggerSleepAction( 5.00 )
    call DisplayTextToForce( GetPlayersAll(), ( "Closing Gate #: " + I2S(i) ) )
    call DestructableRestoreLife(udg_U_Gate[i], 1000000000.00, true)
    call SetDestructableAnimation(udg_U_Gate[i], "stand")
    set udg_U_gateIsOpen[i] = false
endfunction

function Trig_Open_Unlocked_Gate takes nothing returns nothing
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = udg_NUM_UNLOCKED_GATES
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        if ( Trig_Open_Unlocked_Gate_Func001() ) then
            call Trig_Open_Unlocked_Gate_Func002(bj_forLoopAIndex)
            set bj_forLoopAIndex = bj_forLoopAIndexEnd
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
endfunction

function Trig_Trigger_Unlocked_Gates takes nothing returns nothing
    call DisplayTextToForce( GetPlayersAll(), "Door Triggered" )
    set udg_tempPoint[1] = GetUnitLoc(GetEnteringUnit())
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = udg_NUM_UNLOCKED_GATES
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        if ( RectContainsLoc(udg_U_Region[bj_forLoopAIndex], udg_tempPoint[1]) == true ) then
            set udg_tempRegion[1] = udg_U_Region[bj_forLoopAIndex]
            set bj_forLoopAIndex = bj_forLoopAIndexEnd
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    call RemoveLocation(udg_tempPoint[1])
    call Trig_Open_Unlocked_Gate()
endfunction

//===========================================================================
function InitTrig_Trigger_Unlocked_Gates takes nothing returns nothing
    call InitializeGameConstants(  )
    set gg_trg_Trigger_Unlocked_Gates = CreateTrigger(  )
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = udg_NUM_UNLOCKED_GATES
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        call TriggerRegisterEnterRectSimple( gg_trg_Trigger_Unlocked_Gates, udg_U_Region[bj_forLoopAIndex])
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    call TriggerAddAction( gg_trg_Trigger_Unlocked_Gates, function Trig_Trigger_Unlocked_Gates )
endfunction
 
Last edited:
Status
Not open for further replies.
Top