• Check out the results of the Techtree Contest #19!
  • 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.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

Player Group: add/remove player leaks? [Solved]

Level 8
Joined
Jun 1, 2009
Messages
137
Hi! Does adding\removing players to a player group leaks? Will it leak if the player group become empty?
My goal is to display a text messages for a certain players.
Atm I'm using a tempPlayerGroup, but ain't that less efficient rather than creating one constant player group?
Example:

  • Hinit
    • Events
    • Conditions
    • Actions
      • Custom script: set udg_A = CreateForce()
      • Player Group - Add Player 1 (Red) to A
      • Player Group - Add Player 2 (Blue) to A
  • Hon
    • Events
      • Player - Player 1 (Red) types a chat message containing -hon as A substring
      • Player - Player 2 (Blue) types a chat message containing -hon as A substring
    • Conditions
    • Actions
      • Player Group - Add (Triggering player) to A
  • Hoff
    • Events
      • Player - Player 1 (Red) types a chat message containing -hoff as A substring
      • Player - Player 2 (Blue) types a chat message containing -hoff as A substring
    • Conditions
    • Actions
      • Player Group - Remove (Triggering player) from A.
  • Hint
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
    • Actions
      • Game - Display to A the text: Hint!
 
Hey! No--adding/removing players to a player group doesn't leak.

And yes, a constant player group that you use throughout the map is usually better than creating and destroying one each time.

I always encourage folks not to worry too much about leaks for one-off objects. After all, if the object is still useful for your code, then it isn't technically a leak! :grin: Just try to clean up the objects you no longer "need" or that you are losing reference to (e.g. you expect to re-assign that variable to something else, so that object will no longer have anything "referencing" it). And pay the most attention to the periodic triggers since that is where memory leaks truly add up.
 
Hey! No--adding/removing players to a player group doesn't leak.

And yes, a constant player group that you use throughout the map is usually better than creating and destroying one each time.

I always encourage folks not to worry too much about leaks for one-off objects. After all, if the object is still useful for your code, then it isn't technically a leak! :grin: Just try to clean up the objects you no longer "need" or that you are losing reference to (e.g. you expect to re-assign that variable to something else, so that object will no longer have anything "referencing" it). And pay the most attention to the periodic triggers since that is where memory leaks truly add up.
I have a reason to worry. I'm trying to get rid of constant desyncs for every player at round >= 7 and difficulty = 0. At some point, players got desync-ing one by one. Since the difference between difficulty = 0 and difficulty != 0 are some text messages, I want to replace this:

JASS:
function HintBonus7 takes nothing returns nothing
    local integer i_hg = udg_BMin
    local integer i_hgx = 0
    set udg_MSGH_Gen[7] = ( ( ( udg_DIFFICULTY_Color[0] + udg_DIFFICULTY_Name[0] ) + "|r: " ) + ( ( udg_Player_Color[5] + I2S(udg_BOSS_GOLD[udg_Round]) ) + ( udg_Player_Color[7] + " gold!|r" ) ) )
    loop
        exitwhen i_hg > udg_BMax
        if ( udg_Active_Player[i_hg] == true ) then
        set i_hgx = i_hg - 1
        if GetLocalPlayer() == Player(i_hgx) then 
        call DisplayTextToPlayer(Player(i_hgx), 0, 0, udg_MSGH_Gen[7]) 
        call AdjustPlayerStateBJ( udg_BOSS_GOLD[udg_Round], ConvertedPlayer(i_hg), PLAYER_STATE_RESOURCE_GOLD )
        endif
        endif
        set i_hg = i_hg + 1
    endloop
endfunction

Yup, the messages should not cause a desync. But desyncs still happens. Ofc there is chance that somewhere something got divided by zero (since difficulty = 0) but I haven't found it yet...
 
I have a reason to worry. I'm trying to get rid of constant desyncs for every player at round >= 7 and difficulty = 0. At some point, players got desync-ing one by one. Since the difference between difficulty = 0 and difficulty != 0 are some text messages, I want to replace this:
I think the problem is that you are using
JASS:
call AdjustPlayerStateBJ( udg_BOSS_GOLD[udg_Round], ConvertedPlayer(i_hg), PLAYER_STATE_RESOURCE_GOLD )
inside GetLocalPlayer block.
1) GetLocalPlayer is most often used for functions that can't specify a specific player (only everyone), so I don't see the point in using it here.
2) You shouldn't change anything non-visual, only for a specific player.
What do you think will happen if you create a hero for only one player, and everyone else assumes you don't have a hero? Desyncing will occur.
Here, you set the gold only for a specific player. Other players don't have this information, so when he buy something or otherwise change their gold, they'll be desynced. This happens when the game checks their gold.

Also:
JASS:
function HintBonus7 takes nothing returns nothing
    local integer i_hg = udg_BMin
    local integer i_hgx = 0
    set udg_MSGH_Gen[7] = ( ( ( udg_DIFFICULTY_Color[0] + udg_DIFFICULTY_Name[0] ) + "|r: " ) + ( ( udg_Player_Color[5] + I2S(udg_BOSS_GOLD[udg_Round]) ) + ( udg_Player_Color[7] + " gold!|r" ) ) )
    loop
        exitwhen i_hg > udg_BMax
        // For boolean dont need use "== true" or "== false".
        // For "true" use udg_Active_Player[i_hg]
        // For "false" add "not" before
        if udg_Active_Player[i_hg] then
            set i_hgx = i_hg - 1
            if GetLocalPlayer() == Player(i_hgx) then
                call DisplayTextToPlayer(Player(i_hgx), 0, 0, udg_MSGH_Gen[7])
                // Converted player is useless function, u can use this manually
                // It's easy to remember, in JASS players start from 0, in GUI from 1. So we just subtract 1.
                call AdjustPlayerStateBJ( udg_BOSS_GOLD[udg_Round], Player(i_hg - 1), PLAYER_STATE_RESOURCE_GOLD )
            endif
        endif
        set i_hg = i_hg + 1
    endloop
endfunction
 
I think the problem is that you are using
JASS:
call AdjustPlayerStateBJ( udg_BOSS_GOLD[udg_Round], ConvertedPlayer(i_hg), PLAYER_STATE_RESOURCE_GOLD )
inside GetLocalPlayer block.
Oh thank you! I'm sure that's the glitch I've been looking for! Have to test the fixed one now.

Edit: problem solved! Ofc it was AdjustPlayerStateBJ line inside of GetLocalPlayer(), like Enemy1PK said.

Thanks everybody for help!
 
Last edited:
Back
Top