• 🏆 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!

Hashtables - GUI vs JASS > parameters reversed ?

Status
Not open for further replies.
Level 12
Joined
Feb 27, 2019
Messages
399
Hello,

Sorry if you find it a dummy question: I am currently using hashtable after having read many tutorials. And is it me or in Save/Remove calls, the parameters order is reversed between GUI and JASS ? In particular parent & child keys ?

Exemple:

From many tutorials I read (unfortunately WE doesn't give the parameter names, just "Value")
  • Hashtable - Save *integer* as *Child* of *Parent* in *Hashtable name*
Code:
SaveInteger takes hashtable table, integer parentKey, integer childKey, integer value returns nothing

Maybe it is the reason I've such a hard time cleaning my memory when units dies^^

And an additional question:
Let's suppose I use unit handle ID as parent key. When the unit is removed, is the child table of this parent key automatically removed ? Or do I have to add a trigger "Unit leaves region (Entire Map)" that flush this child table ?
 
Last edited:
Level 20
Joined
May 16, 2012
Messages
635
A lot of JASS functions are reversed when using the GUI interface to fit a proper "reading" code style. Usually when a modder uses the GUI interface they are not so experienced with map making, so to make their understanding easier, blizzard did that.

Warcraft 3 do not clear/revome any leak automatically, that's horrible but its true, so you need to manually flush the child keys or they will never be destroyed. I recommend you use Bribe's GUI Unit Indexer and use the "A Unit is DeIndexed" Event (that would be the UnitIndexEvent becomes equal to 2.00 real variable event if i'm not mistaken).
 
Level 12
Joined
Feb 27, 2019
Messages
399
A lot of JASS functions are reversed when using the GUI interface to fit a proper "reading" code style. Usually when a modder uses the GUI interface they are not so experienced with map making, so to make their understanding easier, blizzard did that.

Warcraft 3 do not clear/revome any leak automatically, that's horrible but its true, so you need to manually flush the child keys or they will never be destroyed. I recommend you use Bribe's GUI Unit Indexer and use the "A Unit is DeIndexed" Event (that would be the UnitIndexEvent becomes equal to 2.00 real variable event if i'm not mistaken).

Thanks buddy. But 1 more question came ^^

When a unit of type hero dies, since heroes are revivable, its handle-id is not released right ? Thus in indexer systems it is not deindexed either ?
So in War 3, if I don't clean them manually, units of type hero are never released and leak memory right ?
 
Level 20
Joined
May 16, 2012
Messages
635
Thanks buddy. But 1 more question came ^^

When a unit of type hero dies, since heroes are revivable, its handle-id is not released right ? Thus in indexer systems it is not deindexed either ?
So in War 3, if I don't clean them manually, units of type hero are never released and leak memory right ?

A unit exists after its death only while its corpse exists, and that its adjustable in the gameplay constants tab, so heroes are revivable only for that duration. If you are having problems on death events specifically than use the event "A unit Dies" and do your cleaning there. I recommended a Unit Indexer so you can have access to a powerfull tool when it comes to create MUI code, its also handy for situations like yours. Always keep in mind that most of stuff in warcraft leaks, as a GUI user you should be specially attent to groups, locations and effects since these are the types most used by GUI'ers. There will be occasions when a simple value stored in an hashtable will leak, like your case, and those are the hardest to spot by new modders, so just keep experimenting and if you have doubts ask the hive community for help.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
Thanks buddy. But 1 more question came ^^

When a unit of type hero dies, since heroes are revivable, its handle-id is not released right ? Thus in indexer systems it is not deindexed either ?
So in War 3, if I don't clean them manually, units of type hero are never released and leak memory right ?

Right, you'd have to call RemoveUnit on that hero to get it ejected from the game.
 
Level 12
Joined
Feb 27, 2019
Messages
399
Right, you'd have to call RemoveUnit on that hero to get it ejected from the game.

Thanks both of you. So I have to add a trigger to remove the heroes I am sure I won't revive. Also I can set up an unit indexer to use arrays instead of hashtables, and have deindexing event :)

Just an additionnal question about array variables, since I am not used to them. On de-index event :
- If myarray is a global of raw types (integer, real, string, ...), do I have to do something about myarray[UDex] to avoid memory waste ?
- If myarray is a global of complex types (units, sounds, effects, ...), do I have to null the reference to avoid reference-memory-leaks ?
- If myarray is a local variableof complex types (units, sounds, effects, ...), do I have to null the references to avoid reference-memory-leaks ?
 
Level 12
Joined
Feb 27, 2019
Messages
399
Global arrays in JASS are fixed in size and do not need to be nullified as their data will eventually be overwritten.

The JASS pointers are not correctly recycled so when using agents (unit, location) local variables should be nulled.

Alternatively, if you use Lua, locals do not need to be nulled.

Okay. So if I understand well:
- local agent variable (normal or array): null the value to avoid reference leak (for ex: after DestroyGroup, RemoveUnit, ...)
- global agent variable: i can null it if I want (to avoid invalid pointers), but it is not necessary since it will be overwritten when ID will be reused by War3.

Correct ? :)

And here I can find all the children types of agent.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
Okay. So if I understand well:
- local agent variable (normal or array): null the value to avoid reference leak (for ex: after DestroyGroup, RemoveUnit, ...)
- global agent variable: i can null it if I want (to avoid invalid pointers), but it is not necessary since it will be overwritten when ID will be reused by War3.

Correct ? :)

And here I can find all the children types of agent.
Yes that is all correct.
 
Status
Not open for further replies.
Top