Additional parameters at call

Deele

New Member
Reaction score
0
I am trying to optimize my 4 triggers into 3 functions (war3 editor converted them making 8 functions for each trigger, making total of 32 functions)...
JASS:
function Trig_Auto_balance_Conditions takes nothing returns boolean
    if ( GetPlayerController(GetOwningPlayer(GetEnteringUnit())) == MAP_CONTROL_COMPUTER ) then
        return true
    endif
    return false
endfunction

function Trig_Auto_balance_Actions takes integer p1, integer p2, integer p3 returns nothing
    if (GetPlayerSlotState(Player(p1)) == PLAYER_SLOT_STATE_EMPTY and GetPlayerSlotState(Player(p2)) == PLAYER_SLOT_STATE_EMPTY and GetPlayerSlotState(Player(p3)) == PLAYER_SLOT_STATE_EMPTY ) then
        call RemoveUnit( GetEnteringUnit() )
    endif
endfunction

//===========================================================================
function InitTrig_Auto_balance takes nothing returns nothing
    // For green corner
    set gg_trg_Auto_balance_AtGreen = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_Auto_balance_AtGreen, gg_rct_100 )
    call TriggerAddCondition( gg_trg_Auto_balance_AtGreen, Condition( function Trig_Auto_balance_Conditions ) )
    call TriggerAddAction( gg_trg_Auto_balance_AtGreen, function Trig_Auto_balance_Actions(0, 2, 6) )
    // For yellow corner
    set gg_trg_Auto_balance_AtYellow = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_Auto_balance_AtYellow, gg_rct_200 )
    call TriggerAddCondition( gg_trg_Auto_balance_AtYellow, Condition( function Trig_Auto_balance_Conditions ) )
    call TriggerAddAction( gg_trg_Auto_balance_AtYellow, function Trig_Auto_balance_Actions(1, 2, 4) )
    // For orange corner
    set gg_trg_Auto_balance_AtOrange = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_Auto_balance_AtOrange, gg_rct_300 )
    call TriggerAddCondition( gg_trg_Auto_balance_AtOrange, Condition( function Trig_Auto_balance_Conditions ) )
    call TriggerAddAction( gg_trg_Auto_balance_AtOrange, function Trig_Auto_balance_Actions(0, 3, 5) )
    // For pink corner
    set gg_trg_Auto_balance_AtPink = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_Auto_balance_AtPink, gg_rct_400 )
    call TriggerAddCondition( gg_trg_Auto_balance_AtPink, Condition( function Trig_Auto_balance_Conditions ) )
    call TriggerAddAction( gg_trg_Auto_balance_AtPink, function Trig_Auto_balance_Actions(1, 3, 7) )        
endfunction

I guess, I will need to add additional 3 functions...

EDIT: I guess, it will work like that...
JASS:
function Trig_Auto_balance_Conditions takes nothing returns boolean
    if ( GetPlayerController(GetOwningPlayer(GetEnteringUnit())) == MAP_CONTROL_COMPUTER ) then
        return true
    endif
    return false
endfunction

function Trig_Auto_balance_Green_Actions takes nothing returns nothing
    if (GetPlayerSlotState(Player(0)) == PLAYER_SLOT_STATE_EMPTY and GetPlayerSlotState(Player(2)) == PLAYER_SLOT_STATE_EMPTY and GetPlayerSlotState(Player(6)) == PLAYER_SLOT_STATE_EMPTY ) then
        call RemoveUnit( GetEnteringUnit() )
    endif
endfunction

function Trig_Auto_balance_Yellow_Actions takes nothing returns nothing
    if (GetPlayerSlotState(Player(1)) == PLAYER_SLOT_STATE_EMPTY and GetPlayerSlotState(Player(2)) == PLAYER_SLOT_STATE_EMPTY and GetPlayerSlotState(Player(4)) == PLAYER_SLOT_STATE_EMPTY ) then
        call RemoveUnit( GetEnteringUnit() )
    endif
endfunction

function Trig_Auto_balance_Orange_Actions takes nothing returns nothing
    if (GetPlayerSlotState(Player(0)) == PLAYER_SLOT_STATE_EMPTY and GetPlayerSlotState(Player(3)) == PLAYER_SLOT_STATE_EMPTY and GetPlayerSlotState(Player(5)) == PLAYER_SLOT_STATE_EMPTY ) then
        call RemoveUnit( GetEnteringUnit() )
    endif
endfunction

function Trig_Auto_balance_Pink_Actions takes nothing returns nothing
    if (GetPlayerSlotState(Player(1)) == PLAYER_SLOT_STATE_EMPTY and GetPlayerSlotState(Player(3)) == PLAYER_SLOT_STATE_EMPTY and GetPlayerSlotState(Player(7)) == PLAYER_SLOT_STATE_EMPTY ) then
        call RemoveUnit( GetEnteringUnit() )
    endif
endfunction
//===========================================================================
function InitTrig_Auto_balance takes nothing returns nothing
    // For green corner
    set gg_trg_Auto_balance_AtGreen = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_Auto_balance_AtGreen, gg_rct_100 )
    call TriggerAddCondition( gg_trg_Auto_balance_AtGreen, Condition( function Trig_Auto_balance_Conditions ) )
    call TriggerAddAction( gg_trg_Auto_balance_AtGreen, function Trig_Auto_balance_Green_Actions )
    // For yellow corner
    set gg_trg_Auto_balance_AtYellow = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_Auto_balance_AtYellow, gg_rct_200 )
    call TriggerAddCondition( gg_trg_Auto_balance_AtYellow, Condition( function Trig_Auto_balance_Conditions ) )
    call TriggerAddAction( gg_trg_Auto_balance_AtYellow, function Trig_Auto_balance_Yellow_Actions )
    // For orange corner
    set gg_trg_Auto_balance_AtOrange = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_Auto_balance_AtOrange, gg_rct_300 )
    call TriggerAddCondition( gg_trg_Auto_balance_AtOrange, Condition( function Trig_Auto_balance_Conditions ) )
    call TriggerAddAction( gg_trg_Auto_balance_AtOrange, function Trig_Auto_balance_Orange_Actions )
    // For pink corner
    set gg_trg_Auto_balance_AtPink = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_Auto_balance_AtPink, gg_rct_400 )
    call TriggerAddCondition( gg_trg_Auto_balance_AtPink, Condition( function Trig_Auto_balance_Conditions ) )
    call TriggerAddAction( gg_trg_Auto_balance_AtPink, function Trig_Auto_balance_Pink_Actions )        
endfunction


EDIT2: And alternative:
JASS:
function Trig_Auto_balance_Conditions takes nothing returns boolean
    if ( GetPlayerController(GetOwningPlayer(GetEnteringUnit())) == MAP_CONTROL_COMPUTER ) then
        return true
    endif
    return false
endfunction

function Check_Slot_State takes integer p1, integer p2, integer p3 returns boolean
    if (GetPlayerSlotState(Player(p1)) == PLAYER_SLOT_STATE_EMPTY and GetPlayerSlotState(Player(p2)) == PLAYER_SLOT_STATE_EMPTY and GetPlayerSlotState(Player(p3)) == PLAYER_SLOT_STATE_EMPTY ) then
        return true
    endif
    return false
endfunction

function Trig_Auto_balance_Green_Actions takes nothing returns nothing
    if ( Check_Slot_State(0, 2, 6) ) then
        call RemoveUnit( GetEnteringUnit() )
    endif
endfunction

function Trig_Auto_balance_Yellow_Actions takes nothing returns nothing
    if ( Check_Slot_State(1, 2, 4) ) then
        call RemoveUnit( GetEnteringUnit() )
    endif
endfunction

function Trig_Auto_balance_Orange_Actions takes nothing returns nothing
    if ( Check_Slot_State(0, 3, 5) ) then
        call RemoveUnit( GetEnteringUnit() )
    endif
endfunction

function Trig_Auto_balance_Pink_Actions takes nothing returns nothing
    if ( Check_Slot_State(1, 3, 7) ) then
        call RemoveUnit( GetEnteringUnit() )
    endif
endfunction

     
//===========================================================================
function InitTrig_Auto_balance takes nothing returns nothing
    // For green corner
    set gg_trg_Auto_balance_AtGreen = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_Auto_balance_AtGreen, gg_rct_100 )
    call TriggerAddCondition( gg_trg_Auto_balance_AtGreen, Condition( function Trig_Auto_balance_Conditions ) )
    call TriggerAddAction( gg_trg_Auto_balance_AtGreen, function Trig_Auto_balance_Green_Actions )
    // For yellow corner
    set gg_trg_Auto_balance_AtYellow = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_Auto_balance_AtYellow, gg_rct_200 )
    call TriggerAddCondition( gg_trg_Auto_balance_AtYellow, Condition( function Trig_Auto_balance_Conditions ) )
    call TriggerAddAction( gg_trg_Auto_balance_AtYellow, function Trig_Auto_balance_Yellow_Actions )
    // For orange corner
    set gg_trg_Auto_balance_AtOrange = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_Auto_balance_AtOrange, gg_rct_300 )
    call TriggerAddCondition( gg_trg_Auto_balance_AtOrange, Condition( function Trig_Auto_balance_Conditions ) )
    call TriggerAddAction( gg_trg_Auto_balance_AtOrange, function Trig_Auto_balance_Orange_Actions )
    // For pink corner
    set gg_trg_Auto_balance_AtPink = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_Auto_balance_AtPink, gg_rct_400 )
    call TriggerAddCondition( gg_trg_Auto_balance_AtPink, Condition( function Trig_Auto_balance_Conditions ) )
    call TriggerAddAction( gg_trg_Auto_balance_AtPink, function Trig_Auto_balance_Pink_Actions )        
endfunction
 

Deele

New Member
Reaction score
0
I guess, I still need a help... I got errors from war3 parser:
JASS:
    set gg_trg_Auto_balance_AtGreen = CreateTrigger(  ) //==== ERROR: EXPECTED A VARIABLE NAME
    call TriggerRegisterEnterRectSimple( gg_trg_Auto_balance_AtGreen, gg_rct_100 ) //==== ERROR: EXPECTED A NAME
    call TriggerAddCondition( gg_trg_Auto_balance_AtGreen, Condition( function Trig_Auto_balance_Conditions ) ) //==== ERROR: EXPECTED A NAME
    call TriggerAddAction( gg_trg_Auto_balance_AtGreen, function Trig_Auto_balance_Green_Actions ) //==== ERROR: EXPECTED A NAME
 

T.s.e

Wish I was old and a little sentimental
Reaction score
133
gg_trg variables need to have a user-made trigger with the same name to compile properly. Use local triggers instead.

Such as:
JASS:
local trigger t1 = CreateTrigger()
 

Deele

New Member
Reaction score
0
Yeah, it works:
JASS:
function trg_Autobalance_Conditions takes nothing returns boolean
    if ( GetPlayerController(GetOwningPlayer(GetEnteringUnit())) == MAP_CONTROL_COMPUTER ) then
        return true
    endif
    return false
endfunction

function trg_Autobalance_Check_Slot_State takes integer p1, integer p2, integer p3 returns boolean
    if (GetPlayerSlotState(Player(p1)) == PLAYER_SLOT_STATE_EMPTY and GetPlayerSlotState(Player(p2)) == PLAYER_SLOT_STATE_EMPTY and GetPlayerSlotState(Player(p3)) == PLAYER_SLOT_STATE_EMPTY ) then
        return true
    endif
    return false
endfunction

function trg_Autobalance_Green_Actions takes nothing returns nothing
    if ( trg_Autobalance_Check_Slot_State(0, 2, 6) ) then
        call RemoveUnit( GetEnteringUnit() )
    endif
endfunction

function trg_Autobalance_Yellow_Actions takes nothing returns nothing
    if ( trg_Autobalance_Check_Slot_State(1, 2, 4) ) then
        call RemoveUnit( GetEnteringUnit() )
    endif
endfunction

function trg_Autobalance_Orange_Actions takes nothing returns nothing
    if ( trg_Autobalance_Check_Slot_State(0, 3, 5) ) then
        call RemoveUnit( GetEnteringUnit() )
    endif
endfunction

function trg_Autobalance_Pink_Actions takes nothing returns nothing
    if ( trg_Autobalance_Check_Slot_State(1, 3, 7) ) then
        call RemoveUnit( GetEnteringUnit() )
    endif
endfunction

     
//===========================================================================
function InitTrig_Auto_balance takes nothing returns nothing

    local trigger trg_Autobalance_Green = CreateTrigger(  )
    local trigger trg_Autobalance_Yellow = CreateTrigger(  )
    local trigger trg_Autobalance_Orange = CreateTrigger(  )
    local trigger trg_Autobalance_Pink = CreateTrigger(  )
    
    call TriggerRegisterEnterRectSimple( trg_Autobalance_Green, gg_rct_100 )
    call TriggerAddCondition( trg_Autobalance_Green, Condition( function trg_Autobalance_Conditions ) )
    call TriggerAddAction( trg_Autobalance_Green, function trg_Autobalance_Green_Actions )
    
    call TriggerRegisterEnterRectSimple( trg_Autobalance_Yellow, gg_rct_200 )
    call TriggerAddCondition( trg_Autobalance_Yellow, Condition( function trg_Autobalance_Conditions ) )
    call TriggerAddAction( trg_Autobalance_Yellow, function trg_Autobalance_Yellow_Actions )

    call TriggerRegisterEnterRectSimple( trg_Autobalance_Orange, gg_rct_300 )
    call TriggerAddCondition( trg_Autobalance_Orange, Condition( function trg_Autobalance_Conditions ) )
    call TriggerAddAction( trg_Autobalance_Orange, function trg_Autobalance_Orange_Actions )

    call TriggerRegisterEnterRectSimple( trg_Autobalance_Pink, gg_rct_400 )
    call TriggerAddCondition( trg_Autobalance_Pink, Condition( function trg_Autobalance_Conditions ) )
    call TriggerAddAction( trg_Autobalance_Pink, function trg_Autobalance_Pink_Actions )        
endfunction

I did not know that there is no real difference between declaring trigger into globals or into locals, its works anyway...
 

Sooda

Diversity enchants
Reaction score
318
There is major difference, you can use local variables only inside function where you declared it, when global variables can be used from anywhere.

EDIT:
> I am trying to optimize

Now this is optimized.
JASS:
function Auto_Balance_RemoveUnit takes nothing returns nothing
    call RemoveUnit(GetEnteringUnit())
endfunction

function Auto_Balance_IsControllerComputer takes nothing returns boolean
    return GetPlayerController(GetOwningPlayer(GetEnteringUnit())) == MAP_CONTROL_COMPUTER
endfunction

constant function Auto_Balance_Safe_Boolexpr takes nothing returns boolean
    return true
endfunction

function InitTrig_Auto_balance takes nothing returns nothing
    local trigger balanceTrig = null
    local region denyRegion = CreateRegion()
    local boolean createTrigger = false
    
    if (GetPlayerSlotState(Player(0)) == PLAYER_SLOT_STATE_EMPTY and GetPlayerSlotState(Player(2)) == PLAYER_SLOT_STATE_EMPTY and GetPlayerSlotState(Player(6)) == PLAYER_SLOT_STATE_EMPTY ) then
        // Restrict Green Region
        call RegionAddRect(denyRegion, gg_rct_100)
        set createTrigger = true
    endif

    if (GetPlayerSlotState(Player(1)) == PLAYER_SLOT_STATE_EMPTY and GetPlayerSlotState(Player(2)) == PLAYER_SLOT_STATE_EMPTY and GetPlayerSlotState(Player(4)) == PLAYER_SLOT_STATE_EMPTY ) then
        // Restrict Yellow Region
        call RegionAddRect(denyRegion, gg_rct_200)
        set createTrigger = true
    endif
    
    if (GetPlayerSlotState(Player(0)) == PLAYER_SLOT_STATE_EMPTY and GetPlayerSlotState(Player(3)) == PLAYER_SLOT_STATE_EMPTY and GetPlayerSlotState(Player(5)) == PLAYER_SLOT_STATE_EMPTY ) then
        // Restrict Orange Region
        call RegionAddRect(denyRegion, gg_rct_300)
        set createTrigger = true
    endif
    
    if (GetPlayerSlotState(Player(1)) == PLAYER_SLOT_STATE_EMPTY and GetPlayerSlotState(Player(3)) == PLAYER_SLOT_STATE_EMPTY and GetPlayerSlotState(Player(7)) == PLAYER_SLOT_STATE_EMPTY ) then
        // Restrict Pink Region
        call RegionAddRect(denyRegion, gg_rct_400)
        set createTrigger = true
    endif
    
    if (createTrigger) then
        set balanceTrig = CreateTrigger()
        call TriggerRegisterEnterRegion(balanceTrig, denyRegion, Condition( function Auto_Balance_Safe_Boolexpr))
        call TriggerAddCondition(balanceTrig, Condition( function Auto_Balance_IsControllerComputer))
        call TriggerAddAction( balanceTrig, function Auto_Balance_RemoveUnit)
        
        set denyRegion = null
        set balanceTrig = null
    else
        call RemoveRegion(denyRegion)
        set denyRegion = null
        set balanceTrig = null
    endif
endfunction
 

Deele

New Member
Reaction score
0
I know difference between globals and locals, but I don't know difference between globally set trigger
JASS:
set gg_trg_Auto_balance_AtOrange = CreateTrigger(  )

and locally set trigger
JASS:
local trigger trg_Auto_balance_AtOrange = CreateTrigger(  )


In the end, I think, I need to modify spawning trigger, so it won't need to create unneeded units...
Anyway, Thanks for help T.s.e's and Sooda
 

Flare

Stops copies me!
Reaction score
662
JASS:
set gg_trg_Auto_balance_AtOrange = CreateTrigger(  )

That trigger variable is delcared when you do 'New trigger' - if you change the trigger's name in the left-hand pane, it changes the variable. If your trigger name isn't identical to the variable (other than the gg_trg_ prefix, and underscores replacing spaces) you're going to get an undeclared variable error.
Simplest thing to do is declare a local trigger in your Init function and use that (since, if you ever want to change your trigger's name, there isn't any additional things you must change for compatibility)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top