HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Can someone explain H2I please?

07-31-2006, 04:16 AM#1
n13astra
I dont understand it. I know C/C++ very well but i dont see how this thingo works!!

Can someone explain it to me and maybe give a simple example on how to use it??
07-31-2006, 04:55 AM#2
Alevice
You will hardly ever use it directly.

If you know C, you may know what pointers are. Well, handles are, in a way, that. The handles by themselves don't store anything but the particular "address" of an object (be an unit, destructible, etc, just check which data types extend from handle).

Due to a bug in the game engine, you can retrieve that address as an integer, which can be used for many things.
07-31-2006, 09:10 AM#3
The)TideHunter(
Hm, no.
Handles are just integers. Nothing but integers.
Lets say you have a unit. But he is in a instance of a unit, so saying:

Collapse JASS:
call StoreInteger(Cache(), "SomeStore", "SomeOtherStore", MyUnit)

Wont work, because you cant store a unit like that.
Or any other handle.
So you use H2I and it gives you the handles integer.
Then you can do what you like with it, the index can be stored, gotton back later in another function, and allows a rediculous amount of abuse, which is good.

Example:

Collapse JASS:
function Cache takes nothing returns gamecache
    if(udg_Cache == null) then
        call FlushGameCache(InitGameCache("GC"))
        set udg_Cache = InitGameCache("GC")
    endif
    return udg_Cache
endfunction

function H2I takes handle H returns integer
    return H
    return 0
endfunction

function I2Effect takes integer I returns effect
    return I
    return null
endfunction

function DestroyEffectTimed_Destroy takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local effect e = I2Effect(GetStoredInteger(Cache(), I2S(H2I(t)), "DestroyEffectTimed"))
    call DestroyEffect(e)
    call FlushStoredInteger(Cache, I2S(H2I(t)), "DestroyEffectTimed")
    call DestroyTimer(t)
    set e = null
endfunction

function DestroyEffectTimed takes effect whichEffect, real time returns nothing
    local timer t = CreateTimer()
    call StoreInteger(Cache(), I2S(H2I(t)), "DestroyEffectTimed", I2S(H2I(whichEffect))
    call TimerStart(t, time, false, function DestroyEffectTimed_Destroy)
endfunction

If thats complicated, i will go over it with you.
07-31-2006, 09:12 AM#4
Captain Griffen
Quote:
Originally Posted by Alevice
You will hardly ever use it directly.

Some of us do for the purposes of enhanced flexibility and performance, as the additional function calls of not using it directly makes a slow system slower, and having it directly allows for better understanding of what you are actually doing, so easier troubleshooting.

Quote:
Due to a bug in the game engine, you can retrieve that address as an integer, which can be used for many things.

It's not a bug, it's more a resolution of an incorrect return.
07-31-2006, 09:24 AM#5
The)TideHunter(
Quote:
Originally Posted by Captain Griffen
It's not a bug, it's more a resolution of an incorrect return.

If its incorrect return, it is a bug. And thats why is has the name "return bug".
Everybody calls it that.
07-31-2006, 09:33 AM#6
Captain Griffen
Quote:
Originally Posted by The)TideHunter(
If its incorrect return, it is a bug. And thats why is has the name "return bug".
Everybody calls it that.

When I said incorrect return, I meant the 'return h' where it should be returning an integer. The bug, if there is any, is in the trigger, not in JASS.
07-31-2006, 09:48 AM#7
Mezzer
More or less, but a handle is basicly a top level class that, when converted into a integer, returns it's adress. And it also happens to work the other way around
07-31-2006, 11:40 AM#8
The)TideHunter(
What do you mean by address? the handle IS the integer, all a handle is, is a integer called something else to help people if they use a destructable in a KillUnit action.
Thats the reason why blizz made handles, to stop confusion.
07-31-2006, 01:52 PM#9
SFilip
well that integer is actually an "address" that points to the actual unit/item/trigger/timer/whatever the variable is.
for example if you set that handle to 0, the thing it stored won't be lost, but you won't be able to use it either (unless some other variable stores the same thing).
07-31-2006, 01:59 PM#10
blu_da_noob
Quote:
Originally Posted by The)TideHunter(
What do you mean by address? the handle IS the integer, all a handle is, is a integer called something else to help people if they use a destructable in a KillUnit action.
Thats the reason why blizz made handles, to stop confusion.

So one integer stores all the data for a unit? Buffs, hp, mana, spell cooldown, spell levels etc etc without changing? Handles are integers, but they are integer pointers which 'point' to a place in memory where all the handle's actual data is stored.
08-01-2006, 12:59 PM#11
Chuckle_Brother
Quote:
Originally Posted by The)TideHunter(
What do you mean by address? the handle IS the integer, all a handle is, is a integer called something else to help people if they use a destructable in a KillUnit action.
Thats the reason why blizz made handles, to stop confusion.

Nay, like people have already tried to say, it is effectively a pointer.

If you have C++ or something sometime give it a whirl, use the '&' address operator and view that shit, you will get an 8 character hex value. Thats basically what our, 10 I think, digit long integer effectively is.
08-01-2006, 01:12 PM#12
Mezzer
Right, my bad then
08-01-2006, 05:30 PM#13
Chuckle_Brother
?
08-01-2006, 05:34 PM#14
Mezzer
Quote:
Originally Posted by Mezzer
More or less, but a handle is basicly a top level class that, when converted into a integer, returns it's adress. And it also happens to work the other way around
That's not true so... my bad.
08-01-2006, 06:09 PM#15
Alevice
Sop it turns I was almost right since the beginning.

HA! IN YOUR FACE, LOSERS!

*POOF*