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

Leak Problem

Status
Not open for further replies.
Level 9
Joined
Jun 7, 2008
Messages
440
JASS:
function SetPlayerPrefix takes unit hero returns nothing
    local string txt
    local player player_owner = GetOwningPlayer(hero)
    local integer player_owner_id = GetPlayerId(player_owner)
    set txt = udg_PlayerName[player_owner_id] + " (" + GetUnitName(hero) + ")"
    call SetPlayerName(player_owner, txt)
    set txt = null
    set player_owner = null
endfunction
This works really well. I have a problem though. I have a hero swap function in my map. The swap works surpisingly well. The leak occurs when the heros swap control. How do i switch the prefix names to the opposite player as well?
 
Level 7
Joined
Oct 14, 2008
Messages
340
two things here are so wrong.. you're using the word "leak" which means memory leak, which there is no actual memory leak this is causing..

and putting a hero's name after a player's name is not a prefix, it's a suffix.

now for changing it.. store the player's original name in a variable, so you can refer to it when you want to assign a new suffix :p
 
Level 9
Joined
Jun 7, 2008
Messages
440
Thanks RUI, Though the
  • prefix was because this JASS is a custom script. And i want to call forth the custom script using GUI
  • [code=jass]
  • function StorePlayerNames takes nothing returns nothing
    • local integer index = 0
    • local player player_check
    • loop
      • exitwhen (index > 11)
      • set player_check = Player(index)
      • set udg_PlayerName[index] = GetPlayerName(player_check)
      • set player_check = null
      • set index = index + 1
    • endloop
  • endfunction
  • [/code]
  • I have that function already. But im still new to custom scripts. I would want to call forth the function for the player that triggered the event. As well as the player they swapping with. How would i do that?
 
Last edited:
Level 14
Joined
Nov 23, 2008
Messages
187
There is no reason to nullify player variables, because player count is constant (always 16), and they are precached in memory. So, the function would look simplier:

JASS:
function StorePlayerNames takes nothing returns nothing
    local integer index = 0
    loop
        exitwhen (index > 11)
        set udg_PlayerName[index] = GetPlayerName(Player(index))
        set index = index + 1
    endloop
endfunction

Player that triggered the event is getting with GetTriggerPlayer()
 
Status
Not open for further replies.
Top