function H2I takeshandle h returnsinteger return h return 0 endfunction
The well known H2I function which is very usefull.
stores a handle's address in an integer, allowing various storing systems.
Return bug information by weaaddar:
Quote:
weaaddar:
All variable types in warcraft 3 are four bytes in length. The atomic types (ints, reals, and booleans) use thier four bytes as direct value. Handles use thier four bytes of space as a "pointer" to thier object they references "memory address". I use the terms "pointer" loosely. As they are not first class pointers. As well as "memory address", it is believed all objects are stored in a specific heap and these are thier keys to them. But that is irrelavant.
Anyway, the Jass parser only checks the last return value satiates the return type. Thus we "trick" it into taking a handle when it really was meant to take an integer.
Converting the integer address of the handle back to a handle is done using functions like this:
function I2U takesinteger i returnsunit return i returnnull endfunction function I2Trigger takesinteger i returnstrigger return i returnnull endfunction function I2Timer takesinteger i returnstimer return i returnnull endfunction
Ex: if you converted a unit to an integer you will have to use I2U(ConvertedUnit) to retain the unit. For a trigger you would have to use I2Trigger(ConvertedTrigger)
NOTE: Do not use this on handles like
lightning, ubersplat, texttag, damagetype, attacktype, weapontype and playerstate
as some of them have similar ids.
Thanks to SuperIKI and Peppar for discovering this function.
Only submit your own resources unless permission quoted/stated.
This isn't your own.
__________________
Quote:
[20-00-13] MasterHaosis: Because I am retarded douchebag [20-15-23] MasterHaosis: I am faggot, retard and such.. [20-21-22] MasterHaosis: because I am chat moderator. And you dont have right to speak against me ~Void~: Knock it off, for fuck's sake. Get that bullshit out of your signature and stop being so immature. Let it die out.
It had an author. I wasn't involved in JASS work back then, but I bet one of the older JASSers would be likely to know.
__________________
Quote:
[20-00-13] MasterHaosis: Because I am retarded douchebag [20-15-23] MasterHaosis: I am faggot, retard and such.. [20-21-22] MasterHaosis: because I am chat moderator. And you dont have right to speak against me ~Void~: Knock it off, for fuck's sake. Get that bullshit out of your signature and stop being so immature. Let it die out.
It's used for storing data to stuff through a gamecache, since each handle has a different ID, each gamecache slot will be different, allowing for you to store data under the same name to several different objects (usually timers) without overlap.
It can also be use for debugging, storing to custom values, etc, etc.
I did call it H2I, but for some reason it changed automatically to H2i(this also happened when i tryed to preview the thread before posting)
It would be nice if some mod could rename it to H2I.
It is H2I or h2i. Both are used. There was an attempt I believe to move to a standard of lower case for type casting functions, to differentiate more with functions like I2S, etc.
I'd say any 'author-less' resources are only placed by a staff member, with clear indication in the title it is not their work. I'd also recommend that if you put this one in, it gets stickied due to overall importance.
__________________
Quote:
[20-00-13] MasterHaosis: Because I am retarded douchebag [20-15-23] MasterHaosis: I am faggot, retard and such.. [20-21-22] MasterHaosis: because I am chat moderator. And you dont have right to speak against me ~Void~: Knock it off, for fuck's sake. Get that bullshit out of your signature and stop being so immature. Let it die out.
The first JASSer to exploit H2I was SuperIKI followed by Peppar.
Peppar as in Peppars Multiplayer Chess? Cool guy, didn't know he actually participated in the modding scene, I just thought he made his map and that was it.
Yes, that Peppar.
Just check wc3jass.com, he has submitted some nice scripts back then, also used to post at wc3c when there was the good old AI/Jass forum.