• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] What is the function "RemovePlayer" for?

Status
Not open for further replies.
Level 3
Joined
Sep 18, 2008
Messages
60
Need help with Variable of "player" type

Hello there :)

while agonizing me about leak-prevention, i'm at a point where i want to remove a player variable. The only method i've found was "RemovePlayer" but i think this is a function to kick someone... am i right?

So... does a "player" value leak? How to prevent this?

for example here's a copy of my trigger (it's in a loop)...


  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • ((Picked player) controller) equals to Benutzer
      • ((Picked player) slot status) equals to Spielt
    • Then - Actions
      • Set tmp_Spieler = (Picked player)
      • Set tmp_Spielernummer = (Player number of tmp_Spieler)
      • Set tmp_Spielername = (Name of tmp_Spieler)
      • Leaderboard - Add tmp_Spieler to (Last created leaderboard) with label tmp_Spielername and value Punkte[tmp_Spielernummer]
      • Custom script: call RemovePlayer(udg_tmp_Spieler) // this doesn't work...
      • Else -Actions
 
Last edited:
Level 16
Joined
Jul 21, 2008
Messages
1,121
I've been looking into that function and this is what i havo found out:

JASS:
native RemovePlayer     takes player whichPlayer, playergameresult gameResult returns nothing
//gameResult should be PLAYER_GAME_RESULT_DEFEAT or PLAYER_GAME_RESULT_VICTORY

I think it removes player out of game with victory / loose, WITHOUT REMOVING UNITS
 
Hello there :)

while agonizing me about leak-prevention, i'm at a point where i want to remove a player variable. The only method i've found was "RemovePlayer" but i think this is a function to kick someone... am i right?

So... does a "player" value leak? How to prevent this?

for example here's a copy of my trigger (it's in a loop)...


  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • ((Picked player) controller) equals to Benutzer
      • ((Picked player) slot status) equals to Spielt
    • Then - Actions
      • Set tmp_Spieler = (Picked player)
      • Set tmp_Spielernummer = (Player number of tmp_Spieler)
      • Set tmp_Spielername = (Name of tmp_Spieler)
      • Leaderboard - Add tmp_Spieler to (Last created leaderboard) with label tmp_Spielername and value Punkte[tmp_Spielernummer]
      • Custom script: call RemovePlayer(udg_tmp_Spieler) // this doesn't work...
      • Else -Actions

Players do not leak. Their values are constants - they can only point to one of 12 actual objects, a new object is not created when you create a player. Just a new pointer to an object, and global pointers do not leak, it's just the things that they point to which leak. I hope you understand me... In short, players don't leak.
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
Objects leak when you don't need to use them anymore.

Now, in 99,99% of the cases, you'll still need to use a player because, obviously, you want the player to stay in the game. Thus, you don't want to remove players unless you really want to remove them from the game by e.g. kicking them.
 
Level 8
Joined
Aug 6, 2008
Messages
451
I dont think local handle variable leaks if the object it is pointing to is still in the game.
 
Level 8
Joined
Aug 6, 2008
Messages
451
If local handle variable is pointing to removed object it leaks, thats why you should null local handles.

Nulling local player variables is no needed if you dont remove those players.
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
You need to null local variables because of a bug (thanks, blizzard) related to the handle Id recycler. Every handle has a unique id which identifies this handle from another. Now, when a handle is being removed, normally the handle ID should become available for use again for another object. However, due to a bug, if you don't null handle variables, the handle ID isn't released and cannot be reused by another handle.

So it technically isn't a leak and won't cause any lag, but you better do it anyway so the handle id can be reused by other handles. Only functions like RemoveLocation will fix leaks.

As you'll never be creating any new players (you technically can't), it doesn't matter if you null player variables or not.
 
Level 3
Joined
Sep 18, 2008
Messages
60
Nulling doesn't fix leaks. It's done for another reason.

That's wrong. There's a very good tutorial here
That explains why... "10. Variable leaking"

EDIT: Okay let's say to "nullify" is a "part" of preventing leaks ;) i think that's a description we all can live with :p

------------------------------------------------------------------------

So now in case of my example - do i have to remove the player var? and if yes, how?
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
That's wrong. There's a very good tutorial here
That explains why... "10. Variable leaking"

EDIT: Okay let's say to "nullify" is a "part" of preventing leaks ;) i think that's a description we all can live with :p

------------------------------------------------------------------------

So now in case of my example - do i have to remove the player var? and if yes, how?

That tutorial is wrong. At least, it gives the wrong reason why you need to null those variables. If that reason were to be correct, you would also have to set integers to 0, reals to 0.0 and booleans to false.

And in your example: no you don't need to remove the player, nor do you need to null it.
 
Level 3
Joined
Sep 18, 2008
Messages
60
If that reason were to be correct, you would also have to set integers to 0, reals to 0.0 and booleans to false.
now you're overacting :p and the text is not giving an idea of that to me.

numeric variables have a language-depending fixed size because their value is saved binary. For example 542 will be saved as "0010 0001 1110" so you can't "null" a numeric variable. an integers range is -2^31 up to (2^31)-1 and unsigned int from 0 to (2^32)-1 that's 4KB no matter what it's content is ("null" or any number). And that's what he says in the tutorial - okay okay :D , he doesnt explain why in any way but he mentioned that it's not needed to null numeric variables - But I'll have a closer look at the tut to see which confusing reason that he wrote you've found :)

EDIT: Got it :) "After the wait we have removed the unit. However, the memory still contains something, even though the unit is removed. And so, we need to give it the initial value: null." if it's this clause i totally agree... its a bit ~fungous/spongy~ (not that accurate) like we'd say in germany ^^
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
A handle is a smart pointer. A pointer is nothing more than a numeric variable containing a memory adress.

"null" is an "impossible" pointer value. Most applications use an unreachable memory adress as the null value so the application crashes if you were to refer to null. But fact is that null is still a value which is interpreted as to be pointing to "nowhere". Setting a pointer to the null value does NOT remove the pointer from the memory. It literally sets its "numerical" value to an inexistant adress, the "null" adress.
The memory that's used by the memory is automatically removed upon ending the function just like memory consumed by integers, reals and booleans are also removed.

Besides, the initial value of a pointer/handle isn't necessarily null.
 
Level 3
Joined
Sep 18, 2008
Messages
60
But fact is that null is still a value which is interpreted as to be pointing to "nowhere"

afaik this depends on the programming language - i'm not in to Jass so you'll be right. But in C++ "Null" is defined as "0" and in C it's like you've said (cast to a void pointer).

ok now it's 00:37 am here :p we should continue tomorrow (my brain is getting too slow to follow :p ) ^^ thank you for all your explanatory notes :thumbs_up:
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
I you two want to carry on arguing, do it through PMs or other - this thread is solved, therefore it needs no more discussion.

It's oklino's own thread. I think that if he wants to continue a discussion, its his own right to consider a thread solved or not solved...

afaik this depends on the programming language - i'm not in to Jass so you'll be right. But in C++ "Null" is defined as "0" and in C it's like you've said (cast to a void pointer).

That's right and I don't know myself how jass handles "null". But in c++, the "0" adress is translated into an unreachable memory adress by the compiler. By dereferencing your 0 pointer, your application will crash because the operating system will detect that you're trying to access memory that wasn't allocated for the application.
 
Status
Not open for further replies.
Top