HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Is it bad to do this?

05-12-2007, 07:46 PM#1
Moss
I heard that I2H can be problematic, so is it bad to treat ability variables like integers and vice versa? I don't understand what the problem with I2H could be.
05-12-2007, 07:59 PM#2
Captain Griffen
I2H is bad because WC3 doesn't expect it, so isn't coded defensively against it, and also doesn't have proper referencing (it is for the handle slot, not handle itself). It leaves you open to major screw ups if the handle stack gets corrupted.

Ability variables are integers.
05-12-2007, 07:59 PM#3
Earth-Fury
Quote:
Originally Posted by Moss
I heard that I2H can be problematic, so is it bad to treat ability variables like integers and vice versa? I don't understand what the problem with I2H could be.
You should NEVER cast from a type that has some built in type saftey to one that doesn't (like handle to integer) and then back. you remove the type saftey, then attempt to regain it. Which can cause seriouse issues.
if by ability variables you mean rawcodes like 'U004' , then those alredy are integers. (using a base 256 number system (ASCII))
05-13-2007, 12:42 AM#4
Moss
But CS_Cache uses I2H it right? So it can work a lot of the time. What can cause it to fail?
05-13-2007, 04:54 AM#5
Tide-Arc Ephemera
I don't mean to sound stupid or go off topic, but what's 12H?
05-13-2007, 06:25 AM#6
Ammorth
Collapse JASS:
function H2I takes handle h returns integer
    return h
    return 0
endfunction

function I2U takes integer i returns unit
    return i
    return null
endfunction

They are used to get the unique handle id (stored as an integer) of a handle, which can then be used as a string as a gamecache label to "store" values to. It occurs because the Wc3 syntax checker only checks the last return of a function, which in this case, is valid. Since the other return happens first, it forces the handle to an integer, and returns it. There are numerous problems with it though, and it's not recommended to use it by yourself, unless you know what you are doing.
05-13-2007, 08:21 AM#7
Captain Griffen
Quote:
Originally Posted by Moss
But CS_Cache uses I2H it right? So it can work a lot of the time. What can cause it to fail?

I believe the newer versions use structs, rather than I2H, because of this very reason.
05-13-2007, 09:09 AM#8
Toadcop
A lot of dynamic creation\destroing is SHIT and unsave !
and btw ! you can get stack corruption anyway but if you are using native type it will "align" (a sign a new handle to this multiple one) and after some time all objects will be fine but if you have used H2I to store on it this data
1) will be lost
2) will be "attached" to another object

whats avoiding using H2I I2H will not preventing handle stack corruption (HSC ^^)

HSC is awesome to make you crazy ;) (i got it Vex got it and some other guys too ;))
05-13-2007, 11:33 AM#9
blu_da_noob
I think a lot of people in this thread are talking about H2I, not I2H. I2H on a handle index which doesn't exist will (I think) just give you a null variable. Not much you can do with handles though. If you try to do something like I2U(H2I(someitem)) you'll just get a null variable, as there is some kind of internal type protection.
05-13-2007, 05:25 PM#10
Toadcop
Quote:
If you try to do something like I2U(H2I(someitem)) you'll just get a null variable, as there is some kind of internal type protection.
and ? it's known to all ! you don't understand my post =) (but it's nothing new ^^ + my Eng is not the best :D )
05-13-2007, 07:38 PM#11
Vexorian
Quote:
Originally Posted by blu_da_noob
I think a lot of people in this thread are talking about H2I, not I2H. I2H on a handle index which doesn't exist will (I think) just give you a null variable. Not much you can do with handles though. If you try to do something like I2U(H2I(someitem)) you'll just get a null variable, as there is some kind of internal type protection.
H2I is perfectly fine. On the other hand I2H is pure evil, avoid it.

Cast from ability (the type) to integer shouldn't hurt, then again I don't think there is any use for that ability type
05-13-2007, 08:10 PM#12
TheSecretArts
first off, why would u use I2H. Its pointless
05-13-2007, 09:06 PM#13
Captain Griffen
Quote:
Originally Posted by TheSecretarts
first off, why would u use I2H. Its pointless

Most JASS systems used to be based around I2H. Now preprocessors makes in unnecessary, and its evil has been discovered.
05-13-2007, 10:42 PM#14
Toadcop
the evil is a lame coder...
05-14-2007, 12:33 AM#15
Moss
Quote:
Originally Posted by Vexorian
Cast from ability (the type) to integer shouldn't hurt, then again I don't think there is any use for that ability type

I am storing hotkeys in an array using the abilityId -1093677000 as the index. Since abilities only use up a range of integers equal to the number of abilities you have they can easily fit into an array unless you have more than 8092 or whatever. But for some reason it adds a billion something to all of them, so I subtract it to get a number in the hundreds range. I figure that is the best way to store a list of hotkeys attached to their abilities. But to look up abilities by their hotkey I used pools with the hotkey as the label.

So I don't have to worry because CS_Cache doesn't use I2H anymore. Grim just got me scared in another post because he said it might be why my map is so buggy. I am definitely getting issues that sound like H.S.C. Any pointers on things to avoid doing that cause corruption?