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

No units created?

Status
Not open for further replies.
Level 15
Joined
Nov 30, 2007
Messages
1,202
The Trigger is running, I've checked that. Also if I use this method for about 50 "Towns" Should I create them periodically so to reduce lagg?

JASS:
function SetupBases takes nothing returns nothing
  
  local real array tx      // *** Town Location
  local real array ty      // ***
  local real array rx      // *** Resource Location
  local real array ry      // *** 
  local integer array p    // *** Town Owning Player
  local integer array br   // *** inds Resource to Town
  local integer array res  // *** Resource Unit-Type 
  local integer array rac  // *** Race Town Unit-Type
  local unit u
  local integer a = 0
  local integer random
    
      // Resource and Town Setup
    set tx  [ 0   ] = GetRectCenterX(gg_rct_TL_000)
    set ty  [ 0   ] = GetRectCenterX(gg_rct_TL_000)
    set p   [ 0   ] = 0
    set rac [ 0   ] = 'htow'
    
    set rx  [ 0   ] = GetRectCenterX(gg_rct_RL000_0)
    set ry  [ 0   ] = GetRectCenterY(gg_rct_RL000_0)
    set rx  [ 1   ] = GetRectCenterX(gg_rct_RL001_0)
    set ry  [ 1   ] = GetRectCenterY(gg_rct_RL001_0)
    set rx  [ 2   ] = GetRectCenterX(gg_rct_RL002_0)
    set ry  [ 2   ] = GetRectCenterY(gg_rct_RL002_0)
    set br  [ 0   ] = 0
    set br  [ 1   ] = 0
    set br  [ 2   ] = 0
    
    set tx  [ 1   ] = GetRectCenterX(gg_rct_TL_001)
    set ty  [ 1   ] = GetRectCenterX(gg_rct_TL_001)
    set p   [ 1   ] = 0
    set rac [ 1   ] = 'htow'
    
    set rx  [ 3   ] = GetRectCenterX(gg_rct_RL003_1)
    set ry  [ 3   ] = GetRectCenterY(gg_rct_RL003_1)
    set rx  [ 4   ] = GetRectCenterX(gg_rct_RL004_1)
    set ry  [ 4   ] = GetRectCenterY(gg_rct_RL004_1)
    set rx  [ 5   ] = GetRectCenterX(gg_rct_RL005_1)
    set ry  [ 5   ] = GetRectCenterY(gg_rct_RL005_1)
    set br  [ 3   ] = 1
    set br  [ 4   ] = 1
    set br  [ 5   ] = 1
    
        // Resource Unit-Type 

    set res[0] = 'n000'  // Lumber
    set res[1] = 'n001'  // Food
    set res[2] = 'n002'  // Gold
    set res[3] = 'n003'  // Iron
    
    
      // Create Town

    loop 
      exitwhen a > 1 // Number of Town Location Arrays Used 
        set u = CreateUnit(Player(p[a]), rac[a], tx[a], ty[a], bj_UNIT_FACING )
        call indexUnit(u)
        set u = null
        set a = a + 1
      endloop

  set a = 0
  
      // Create Resources
    loop 
      exitwhen a > 5 // Number of Resource Location Arrays
        set random = GetRandomInt(0,3)
        set u = CreateUnit(Player(p[a]), res[random], rx[a], ry[a], bj_UNIT_FACING )
        call GroupAddUnit(udg_indexedUnit_g[br[a]], u)
        call indexUnit(u)
        set u = null
        set a = a + 1
    endloop

    call DestroyTrigger(gg_trg_SetupBases)

endfunction

//===========================================================================
function InitTrig_SetupBases takes nothing returns nothing
  local trigger t = CreateTrigger()
    set gg_trg_SetupBases = t
    call TriggerAddAction(t, function SetupBases)
  set t = null
endfunction
 
Last edited:
this
JASS:
set ty  [ 0   ] = GetRectCenterX(gg_rct_TL_000)

should probably be this
JASS:
set ty  [ 0   ] = GetRectCenterY(gg_rct_TL_000)

also this
JASS:
set ty  [ 1   ] = GetRectCenterX(gg_rct_TL_001)

should be this
JASS:
set ty  [ 1   ] = GetRectCenterY(gg_rct_TL_001)

also change this
JASS:
function InitTrig_SetupBases takes nothing returns nothing
  local trigger t = CreateTrigger()
    set gg_trg_SetupBases = t
    call TriggerAddAction(t, function SetupBases)
  set t = null
endfunction

to this
JASS:
function InitTrig_SetupBases takes nothing returns nothing
  local trigger t = CreateTrigger()
  call TriggerAddAction(t, function SetupBases)
  set t = null
endfunction

and take out this
JASS:
call DestroyTrigger(gg_trg_SetupBases)
 
Level 15
Joined
Nov 30, 2007
Messages
1,202
this
JASS:
set ty  [ 0   ] = GetRectCenterX(gg_rct_TL_000)

should probably be this
JASS:
set ty  [ 0   ] = GetRectCenterY(gg_rct_TL_000)

also this
JASS:
set ty  [ 1   ] = GetRectCenterX(gg_rct_TL_001)

should be this
JASS:
set ty  [ 1   ] = GetRectCenterY(gg_rct_TL_001)

also change this
JASS:
function InitTrig_SetupBases takes nothing returns nothing
  local trigger t = CreateTrigger()
    set gg_trg_SetupBases = t
    call TriggerAddAction(t, function SetupBases)
  set t = null
endfunction

to this
JASS:
function InitTrig_SetupBases takes nothing returns nothing
  local trigger t = CreateTrigger()
  call TriggerAddAction(t, function SetupBases)
  set t = null
endfunction

and take out this
JASS:
call DestroyTrigger(gg_trg_SetupBases)

I shame myself again, it's that damn blue background and my eyes...!

I am calling the trigger with execute from the first setup trigger and then I figured I could destroy it? You sure I should take out the destroyTrigger? The global trigger variable is staying, someone already corrected that misstake for me earlier! ;P
 
Level 15
Joined
Nov 30, 2007
Messages
1,202
If u have jngp create a globals block and make ur own trigger variable the gg_trg leaks when it is used so create ur own to call trigger execute and trigger destroy

Not sure how to do that, would this be correct? Can't be since it returns a syntax :p


oh scratch that, you declare them on the trigger you want stored

JASS:
globals
    trigger playerSetup = gg_trg_PlayerSetup
endglobals

function InitTrig_PlayerSetup takes nothing returns nothing
 // Do stuff
endfunction
JASS:
function InitTrig_Init takes nothing returns nothing
    call TriggerExecute(playerSetup)
    call DestroyTrigger(playerSetup)
endfunction

So I dont need to use the variables menu no more? :eek: Can I declare all global triggers inside any trigger or only where it is used like the example above?
 
Last edited:
i prefer to do it like this
just make sure to change the variables i told u to change earlier although i changed the ones i remembered

JASS:
globals
    trg_SetupBases
endglobals

function SetupBases takes nothing returns nothing
  
  local real array tx      // *** Town Location
  local real array ty      // ***
  local real array rx      // *** Resource Location
  local real array ry      // *** 
  local integer array p    // *** Town Owning Player
  local integer array br   // *** inds Resource to Town
  local integer array res  // *** Resource Unit-Type 
  local integer array rac  // *** Race Town Unit-Type
  local unit u
  local integer a = 0
  local integer random
    
      // Resource and Town Setup
    set tx  [ 0   ] = GetRectCenterX(gg_rct_TL_000)
    set ty  [ 0   ] = GetRectCenterY(gg_rct_TL_000)
    set p   [ 0   ] = 0
    set rac [ 0   ] = 'htow'
    
    set rx  [ 0   ] = GetRectCenterX(gg_rct_RL000_0)
    set ry  [ 0   ] = GetRectCenterY(gg_rct_RL000_0)
    set rx  [ 1   ] = GetRectCenterX(gg_rct_RL001_0)
    set ry  [ 1   ] = GetRectCenterY(gg_rct_RL001_0)
    set rx  [ 2   ] = GetRectCenterX(gg_rct_RL002_0)
    set ry  [ 2   ] = GetRectCenterY(gg_rct_RL002_0)
    set br  [ 0   ] = 0
    set br  [ 1   ] = 0
    set br  [ 2   ] = 0
    
    set tx  [ 1   ] = GetRectCenterX(gg_rct_TL_001)
    set ty  [ 1   ] = GetRectCenterY(gg_rct_TL_001)
    set p   [ 1   ] = 0
    set rac [ 1   ] = 'htow'
    
    set rx  [ 3   ] = GetRectCenterX(gg_rct_RL003_1)
    set ry  [ 3   ] = GetRectCenterY(gg_rct_RL003_1)
    set rx  [ 4   ] = GetRectCenterX(gg_rct_RL004_1)
    set ry  [ 4   ] = GetRectCenterY(gg_rct_RL004_1)
    set rx  [ 5   ] = GetRectCenterX(gg_rct_RL005_1)
    set ry  [ 5   ] = GetRectCenterY(gg_rct_RL005_1)
    set br  [ 3   ] = 1
    set br  [ 4   ] = 1
    set br  [ 5   ] = 1
    
        // Resource Unit-Type 

    set res[0] = 'n000'  // Lumber
    set res[1] = 'n001'  // Food
    set res[2] = 'n002'  // Gold
    set res[3] = 'n003'  // Iron
    
    
      // Create Town

    loop 
      exitwhen a > 1 // Number of Town Location Arrays Used 
        set u = CreateUnit(Player(p[a]), rac[a], tx[a], ty[a], bj_UNIT_FACING )
        call indexUnit(u)
        set u = null
        set a = a + 1
      endloop

  set a = 0
  
      // Create Resources
    loop 
      exitwhen a > 5 // Number of Resource Location Arrays
        set random = GetRandomInt(0,3)
        set u = CreateUnit(Player(p[a]), res[random], rx[a], ry[a], bj_UNIT_FACING )
        call GroupAddUnit(udg_indexedUnit_g[br[a]], u)
        call indexUnit(u)
        set u = null
        set a = a + 1
    endloop

    call DestroyTrigger(trg_SetupBases)

endfunction

//===========================================================================
function InitTrig_SetupBases takes nothing returns nothing
    set trg_SetupBases = CreateTrigger()
    call TriggerAddAction(trg_SetupBases, function SetupBases)
endfunction
 
Level 15
Joined
Nov 30, 2007
Messages
1,202
JASS:
function InitTrig_Init takes nothing returns nothing
    call TriggerExecute(trg_playerSetup)
    call TriggerExecute(trg_baseSetup) 
endfunction
JASS:
globals
    trigger trg_playerSetup
endglobals

function PlayerSetup takes nothing returns nothing
    call BJDebugMsg("Player Setup!")
    call DestroyTrigger(trg_playerSetup) 
    
endfunction

function InitTrig_PlayerSetup takes nothing returns nothing
    set trg_playerSetup = CreateTrigger()
    call TriggerAddAction(trg_playerSetup, function PlayerSetup)
endfunction
JASS:
globals
    trigger trg_baseSetup
endglobals

function BaseSetup takes nothing returns nothing
    call BJDebugMsg("Base Setup!")
    call DestroyTrigger(trg_baseSetup) 
endfunction

function InitTrig_BaseSetup takes nothing returns nothing
    set trg_baseSetup = CreateTrigger()
    call TriggerAddAction(trg_baseSetup, function BaseSetup)
endfunction

For some reason only the message "Player Setup!" is printed?
 
try this
JASS:
function InitTrig_Init takes nothing returns nothing
    call TriggerExecute(trg_playerSetup)
endfunction

JASS:
globals
    trigger trg_baseSetup
endglobals

function BaseSetup takes nothing returns nothing
    call BJDebugMsg("Base Setup!")
    call DestroyTrigger(trg_baseSetup) 
endfunction

function InitTrig_BaseSetup takes nothing returns nothing
    set trg_baseSetup = CreateTrigger()
    call TriggerAddAction(trg_baseSetup, function BaseSetup)
endfunction

JASS:
globals
    trigger trg_playerSetup
endglobals

function PlayerSetup takes nothing returns nothing
    call BJDebugMsg("Player Setup!")
    call TriggerExecute(trg_baseSetup) 
    call DestroyTrigger(trg_playerSetup) 
endfunction

function InitTrig_PlayerSetup takes nothing returns nothing
    set trg_playerSetup = CreateTrigger()
    call TriggerAddAction(trg_playerSetup, function PlayerSetup)
endfunction

edit: as a note u can only call functions above the function ur calling it from
 
Level 15
Joined
Nov 30, 2007
Messages
1,202
hmm, I've still not quite got a hang of this... I tested again by merging two triggers, Unit dies and just add/remove unit from index by executing it from outside but it doesnt work properly... The Unit is never added even though the function is correctly executed, it is as if the unitToIndex = null

Basically at CheckForIndexUnit the message is printed but the unit is never indexed.

JASS:
globals
    trigger trg_unitIndex
    unit unitToIndex
    group indexGroup
    integer indexCur
    unit array indexUnit
endglobals

// Not running!?
function IndexUnit takes unit u returns nothing
    call SetUnitUserData(u, indexCur)
    set indexUnit[indexCur] = u
    call GroupAddUnit(indexGroup, u)
    set indexCur = indexCur + 1
    call BJDebugMsg("A unit was Indexed!")
endfunction

// Don't know
function DeindexUnit takes unit u returns nothing
    call SetUnitUserData(indexUnit[indexCur], GetUnitUserData(u))
    set indexUnit[GetUnitUserData(u)] = indexUnit[indexCur]
    call GroupRemoveUnit(indexGroup, u)
    set indexCur = indexCur - 1
    call BJDebugMsg("A unit was Deindexed!")
endfunction

// Running!
// This Func is used when the trigger is executed from the outside
function CheckForIndexUnit takes nothing returns nothing
  call BJDebugMsg("Trigger is running from outside?")
    if IsUnitInGroup(unitToIndex, indexGroup) == true then
      call DeindexUnit(unitToIndex)
        else
          call IndexUnit(unitToIndex)
    endif
    set unitToIndex = null
endfunction

// Don't know
// This func takes care of dying IndexUnits
function IndexedUnitDies takes nothing returns boolean
    if IsUnitInGroup(GetDyingUnit(), indexGroup) == true then
    call BJDebugMsg("Indexed Unit was killed!")
endif
return FALSE
endfunction

//===========================================================================
function InitTrig_UnitIndex takes nothing returns nothing
  local trigger t = CreateTrigger()
  set trg_unitIndex = t
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition(t, Condition(function IndexedUnitDies ))
    call TriggerAddAction(t, function CheckForIndexUnit)
  set t = null
endfunction

JASS:
function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
    set unitToIndex = CreateUnitAtLoc(Player(0), 'hfoo', GetRectCenter(GetPlayableMapRect()), bj_UNIT_FACING)
    call TriggerExecute(trg_unitIndex)
endfunction
 
i believe ur problem is this although i can be mistaken but change these
JASS:
      call DeindexUnit(unitToIndex)
        else
          call IndexUnit(unitToIndex)

to this
JASS:
      call DeindexUnit()
        else
          call IndexUnit()

edit: also change this
JASS:
function IndexedUnitDies takes nothing returns boolean
    if IsUnitInGroup(GetDyingUnit(), indexGroup) == true then
    call BJDebugMsg("Indexed Unit was killed!")
endif
return FALSE
endfunction

to this
JASS:
function IndexedUnitDies takes nothing returns boolean
    if IsUnitInGroup(GetDyingUnit(), indexGroup) == true then
    call BJDebugMsg("Indexed Unit was killed!")
return true
else
return false
endif
endfunction

also u should not use createunitatloc anymore use the one tht calls for x and y values

and i just noticed a big problem lol easy one to make tho u never created the group and u cant creategroup in globals block put
JASS:
indexGroup= CreateGroup()
in one of the lines of code but make sure it only initializes the group once
 
Level 15
Joined
Nov 30, 2007
Messages
1,202
Changed unitToIndex to udg_unitToIndex and indexGroup to udg_indexGroup.

Removed the get unit u from the index/deindex functions and still nothing happens.

Even trying killing any unit removing the conditions from unit killed and calling it from there. It seems it just doesnt want to call IndexUnit()

JASS:
// This func takes care of dying IndexUnits
function IndexedUnitDies takes nothing returns boolean
    //if IsUnitInGroup(GetDyingUnit(), udg_indexGroup) == true then
    call BJDebugMsg("Indexed Unit was killed!")
    call IndexUnit()
//endif
return FALSE
endfunction
 
Level 15
Joined
Nov 30, 2007
Messages
1,202
i updated the last post u probably looked at it after i updated it and changing to udg_ wont do anything u have to initialize the group/s

All groups or just when Im using it cus I made a variable the "normal (udg_) way" and it still did have no effect. I even called the function from The dying Unit Coniditon and no DebugMsg was displayed from the IndexUnit func. Is there a bug if I dont set all my Globals properly?

I tried befor changing it to a normal variable the set inxedGroup = CreateGroup() befor the call TriggerExecute(trg_indexUnit)
 
u have to initialize all groups if a group isnt created and u try to check tht group i believe it just stops the function like a mistype or trying to get the value of a variable tht has no value assigned to it
and i was always told not to do
JASS:
globals
    group g = CreateGroup()
endglobals
instead do this
JASS:
globals 
    group g
endglobals

function groupinitialize takes nothing returns nothing 
    set g = CreateGroup()
    // all other groups related to this trigger here
    call triggerremoveaction( triggername, groupinitialize )
endfunction

init trigger takes nothing returns nothing 
    local trigger triggername
    set triggername = CreateTrigger()
    call triggeraddaction ( triggername, groupinitialize() )
    call triggeraddaction( triggername, actions )
    set triggername = null
endfunction

all the typing is not correct im not at my pc also this is just an example
 
Status
Not open for further replies.
Top