Simple init trigger not functional...

WarLuvr3393

Hmmm...too many things to play (WoW, COD4, WC3)
Reaction score
54
Hey guys. I was just working on a map and I wanted to do some cleaning up so I converted my initialization trigger into JASS and attempted to clean up leaks and ugly coding. Here's my current script:

JASS:
function Set_Starting_Gold takes nothing returns nothing
call AdjustPlayerStateBJ(150,GetEnumPlayer(),PLAYER_STATE_RESOURCE_GOLD)
endfunction

function Remove_Units takes nothing returns nothing
call RemoveUnit(GetEnumUnit())
endfunction

function Trig_Intialization_Actions takes nothing returns nothing
local integer i
local group g
  call DisplayTextToForce(GetPlayersAll(),"TRIGSTR_102")
  call SetTimeOfDay(6.0)
  call EnableDawnDusk(false)
  call StopMusic(false)
  call ClearMapMusic()
  call PlayMusic(gg_snd_MainMusic)
  call ForForce(GetPlayersAll(),function Set_Starting_Gold)
  set i = 2
  loop
    exitwhen i > 11
    if GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING then
      call BJDebugMsg("Player " + I2S(i+1) + " is in the game.")
    else
      set g = CreateGroup()
      call GroupEnumUnitsOfPlayer(g, Player(i), null)
      call ForGroup(g, function Remove_Units)
      call DestroyGroup(g)
      call BJDebugMsg("Player " + I2S(i+1) + "'s units have been successfully removed")
    endif
    set g = null
  endloop
endfunction

function InitTrig_Intialization takes nothing returns nothing
local trigger t = CreateTrigger()
  call TriggerAddAction(t,function Trig_Intialization_Actions)
endfunction


Now it's suppose to set the time of day, play music, give gold to players, and remove the units of the players that aren't playing at the moment. Now, for some reason, it's not removing the units of the players not present in the game.

What's the problem here?
 

Exide

I am amazingly focused right now!
Reaction score
448
Try moving

JASS:

      call DestroyGroup(g)
      set g = null


outside of the loops?
 

WarLuvr3393

Hmmm...too many things to play (WoW, COD4, WC3)
Reaction score
54
Try moving

JASS:
      call DestroyGroup(g)
      set g = null


outside of the loops?

Lol, I actually just posted a reply on your topic.

I'll try that. :p

Edit: I tried moving those 2 lines down, outside of the loops and it still doesn't work.
 

Exide

I am amazingly focused right now!
Reaction score
448
Lol, I actually just posted a reply on your topic.

I'll try that. :p

Maybe moving only:

JASS:
      set g = null


will work. -You might need to Destroy it to prevent leaks. :p
 

WarLuvr3393

Hmmm...too many things to play (WoW, COD4, WC3)
Reaction score
54
Maybe moving only:

JASS:
      set g = null


will work. -You might need to Destroy it to prevent leaks. :p

Nope, I made a mistake in the coding. I don't have to destroy it each time since I'm changing the variable to a different value but still using it. I'll only need to remove the leak after it's all done.
 

quraji

zap
Reaction score
144
This works for me:

JASS:

function b takes nothing returns nothing
    call RemoveUnit(GetEnumUnit())
endfunction

function a takes nothing returns nothing
    local integer i = 0
    local group g
    
    loop
      exitwhen i == 12
      
        if GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING then
            call BJDebugMsg("Player " + I2S(i+1) + " is playing.")
        else
            set g = CreateGroup()
            call GroupEnumUnitsOfPlayer(g, Player(i), null)
            
            call ForGroup(g, function b)
            call DestroyGroup(g)
            
            call BJDebugMsg("Player " + I2S(i+1) + "'s units removed.")
        endif
    
        set i = i + 1
    endloop
    
    set g = null
    
endfunction
 

WarLuvr3393

Hmmm...too many things to play (WoW, COD4, WC3)
Reaction score
54
Still doesn't work. I've updated the script in my first post. I don't even see the DebugMsg's...

Help please.
 

quraji

zap
Reaction score
144
If you don't see any messages, that means your function is exiting before it gets to that point. Put back in your old loops because those don't seem to be the problem.

Place BJDebugMsg after each of those starting calls and see where the function exits.
 
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