| 08-18-2004, 01:23 AM | #1 |
I'm just begining to explore handles and the return bug and theres not much to scrap up on them so i have a question about something.. Code:
function H2I takes handle h returns integer return h return 0 endfunction Code:
function H2BLAH takes handle h returns BLAH return h endfunction |
| 08-18-2004, 01:54 AM | #2 |
In most programming languages that second return is whats called "A never reached return statement". Jass only checks that the last return is correct and doesn't care about the other ones. Whats really being returned is the handle itself as when a function is told to return it returns whatever was said then quits teh function. There is another return bug which works only between handle types. The parser only checks that the thing returned in something which returns a handle based type is a handle. So you can do this without a cry of jass's debugger: function H2U takes handle h returns unit return h endfunction This will make it cry though function H2I takes handle h returns integer return h endfunction because integer is NOT handle based. |
| 08-19-2004, 11:42 PM | #3 |
I get it... so if i want to convert a handle to an integer it has to use my first example? but i still dont know what i could use this for.. |
| 08-19-2004, 11:45 PM | #4 |
Gamecache is the universally excepted reason to use the return bug. Basically gamecache only allows you to store primitves, and not handle based types there fore you need to be able to type cast. |
| 08-20-2004, 12:11 AM | #5 |
You can also use the custom value of a unit to store the output of the return bug. Quite often I only need to store 1 reference per unit, so the custom value is all that is required. For example, in my TD I have a "booster" tower with inverse siphon mana, for some reason siphon mana stops after a while even with infinite duration, so i just save the target unit in the custom value and recast siphon mana every so often. In this case the advantage of using the custom value is I can do a simple GUI trigger condition - if Custom Value of unit equal to 0 it has no siphon target. Altough in most cases theres no real advantage of using custom value over game cache, just that if the custom value is otherwise unused, may as well use it. |
| 08-20-2004, 02:15 AM | #6 |
but cant you just save a unit in the gamecache? |
| 08-20-2004, 02:23 AM | #7 |
not quite. When you cache a unit your caching a copy of the unit. What you more likely want to do is cache the units handle (pointer). |
| 08-21-2004, 12:53 AM | #8 |
hmm.. and what would this do? Code:
function H2U takes handle h returns unit return h return null //does null work here? endfunction function afunction takes nothing returns nothing call H2U(10) endfunction |
| 08-21-2004, 02:01 AM | #9 |
you'd just get an integer representing its handle number Your function would do nothing and would give you an error because 10 is not considered a handle but rather an int. |
| 08-21-2004, 01:55 PM | #10 | |
Quote:
Anyways something like 20 of the first handle indexes are all used by the ConvertXXXX() functions. I could determine that ConvertEffectType(1) and ConvertItemType(1) use the same handle that is 1 when using H2I on any of them. These natives seem to be return bug exploiters by blizzard done just to pass arguments in a better way. So anyways I2U(10) (integer to unit) on an integer that isn't one of a unit would returns a random handle type as if it was a unit, All the natives that use handles check it so the arguments are the ones they are supposed to check before doing anything so it would be pretty useless |
| 08-23-2004, 01:11 PM | #11 |
well i did get it to display the integer handle of a normal mountain king.. but then once i converted it back to a unit there were no uses.. i tried making it select the unit i typed in. so i would type in 185601 or whatever the code was and it would select the unit but.. i screwed everything up so it didnt work. thx for the help tho. |
