HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Return bug problem

03-03-2006, 10:55 PM#1
Jiminiyainoda
Hmm, ok so im testing the return bug.
Iv got the functions:

Collapse JASS:
function H2I takes handle h returns integer
    return h
    return 0
endfunction

function H2R takes handle h returns real
    return h
    return 0.00
endfunction

function H2S takes handle h returns string
    return h
    return ""
endfunction

Now, im not sure if some cant be converted into certain parameter types.
Anyways then i have the functions to test:

Collapse JASS:
    set udg_Mkay = GroupPickRandomUnit(GetUnitsInRectAll(GetPlayableMapRect()))
    call DisplayTextToForce( GetPlayersAll(), GetUnitName(udg_Mkay) )
    call DisplayTextToForce( GetPlayersAll(), ("integer:" + I2S(H2I(udg_Mkay))))
    call DisplayTextToForce( GetPlayersAll(), ("real:" + R2S(H2R(udg_Mkay))))
    call DisplayTextToForce( GetPlayersAll(), ("string:" + H2S(udg_Mkay)))
(Yes i know when i set Mkay it leaks, this is just a test though)

So whats going wrong? I get no compile errors, but when it calls the DisplayText functions, i get fatal error.
03-03-2006, 11:00 PM#2
BlinkBoy
i aint sure but the debugg return should return 0 as debugg(always no matter the return varient/handle), try it and then tell me if it worked.
03-03-2006, 11:03 PM#3
Jiminiyainoda
I tried, and it dident work, you cant return 0 for a string or real, default is null for handle, 0 for int, 0.00 for real, or "" for string.
Anything else dosent work
03-03-2006, 11:12 PM#4
BlinkBoy
let me get you the link from where i read that, i don't remenber

http://jass.sourceforge.net/doc/retbug.shtml
03-03-2006, 11:30 PM#5
Blade.dk
Strings are created objects, like handles, so it will only return a valid string if a string with the id of the handle is created at that time.

So when you try to use an invalid string, you gets errors. That is the answer.
03-03-2006, 11:33 PM#6
phyrex1an
Collapse JASS:
function H2S takes handle h returns string
    return h
    return ""
endfunction
Probelby becuse that.
What it does is to convert the integer pointer to the handle to a pointer to a string in the string table that wc3 uses.

But, handle pointers are very huge numbers while string pointers are very low.
So it will return a pointer to a string that doesn't exist at all. So it is more nothing than "" or null.
03-04-2006, 12:04 AM#7
Anitarf
Conversion to real is wrong as well, the handle index is an integer, integers and reals are written differently, you can't just take the same string of bits and use it once as a real and once as an integer and expect it to give you the same number.

The only function that works correctly here is H2I.
03-04-2006, 12:06 AM#8
Jiminiyainoda
O, ok i understand.
Iv just been trying others for the time being lol

Collapse JASS:
//Specific Handle Converts

function C_Unit2Int takes unit u returns integer //Unit handle to Int
    return u
    return 0
endfunction

function C_Int2Unit takes integer i returns unit //Int to Unit Handle
    return i
    return null
endfunction

function C_Group2Int takes group g returns integer //Group handle to Int
    return g
    return 0
endfunction

function C_Int2Group takes integer i returns group //Int to Group handle
    return i
    return null
endfunction

function C_Player2Int takes player p returns integer //Player handle to Int
    return p
    return 0
endfunction

function C_Int2Player takes integer i returns player //Int to Player handle
    return i
    return null
endfunction

function C_Item2Int takes item i returns integer //Item handle to Int
    return i
    return 0
endfunction

function C_Int2Item takes integer i returns item //Item handle to Int
    return i
    return null
endfunction

function C_Ability2Int takes ability a returns integer //Ability handle to Int
    return a
    return 0
endfunction

function C_Int2Ability takes integer i returns ability //Int to Ability handle
    return i
    return null
endfunction

function C_Buff2Int takes buff b returns integer //Buff handle to Int
    return b
    return 0
endfunction

function C_Int2Buff takes integer i returns buff //Int to Buff handle
    return i
    return null
endfunction

function C_Dialog2Int takes dialog d returns integer //Dialog handle to Int
    return d
    return 0
endfunction

function C_Int2Dialog takes integer i returns dialog //Int to Dialog handle
    return i
    return null
endfunction

function C_DialogButton2Int takes button b returns integer //Dialog Button handle to Int
    return b
    return 0
endfunction

function C_Int2DialogButton takes integer i returns button //Int to Dialog Button handle
    return i
    return null
endfunction

function C_Leaderboard2Int takes leaderboard l returns integer //Leaderboard handle to Int
    return l
    return 0
endfunction

function C_Int2Leaderboard takes integer i returns leaderboard //Int to Leaderboard handle
    return i
    return null
endfunction

function C_Lightning2Int takes lightning l returns integer //Lightning handle to Int
    return l
    return 0
endfunction

function C_Int2Lightning takes integer i returns lightning //Int to Lightning handle
    return i
    return null
endfunction

function C_Multiboard2Int takes multiboard m returns integer //Multiboard handle to Int
    return m
    return 0
endfunction

function C_Int2Multiboard takes integer i returns multiboard //Int to Multiboard handle
    return i
    return null
endfunction

function CPlayer2Int takes player p returns integer //Player handle to Int
    return p
    return 0
endfunction

function CInt2Player takes integer u returns player //Int to Player handle
    return i
    return null
endfunction

//All Handle Converts

function C_H2I takes handle h returns integer
    return h
    return 0
endfunction

function C_I2H takes integer i returns handle
    return i
    return null
endfunction

Il make some random global vars up and test to see if it works.
Thx again :)
03-04-2006, 12:09 AM#9
Anitarf
you don't need C_Unit2Int, you can use H2I for everything. You do need individual functions for transformations in the other way, though.
03-04-2006, 12:29 AM#10
Jiminiyainoda
Yea iv got that H2I and I2H at the very bottom, just wanted to fiddle about with it and see what goes with what :D

I looked through common.j and blizzard.j and noticed lots of varibles, such as eventid's, are from other varibles, which are from handles.. a big chain, like a variable conditionfunc is a boolexpr, and a boolexpr is a handle, very interesting, and a unit, item and destructable are widgets, and widgets are handles

Il do some more experimenting.
Thx for extra info
03-04-2006, 01:47 AM#11
Vexorian
messing with return bug and strings is a clear path to get crashes in game
03-04-2006, 01:51 AM#12
BlinkBoy
hmm what about, you want to bann a player but you don't want him to know, if you set if localplayer == (the player) then - and then call him that function would he crash alone?