How to fix "Cannot convert returned value from integer to unit" from maps that only work in 1.20

Level 1
Joined
Jan 2, 2024
Messages
2
Coming back to the game after a long time only to find that Castle Fight v1.13b only runs on versions around 1.20. Trying to port it to newer versions but JassHelper reports "Cannot convert returned value from integer to unit" for function WD. Relevant code snippet below.

The code seems to be cooking something like a unit linked list using unit custom value. I'm not sure if this is the last thing that's preventing newer versions of the game from loading the map, but it is the last error JassHelper prints out when I fixed other double return issues (using GetHandleId).

This was probably already discussed in one thousand other posts, but I can't for the life of me find much relevant info regarding porting broken old maps, especially regarding this particular error. It would be great if anyone can share some pointers for this poor old mapster!

JASS:
function WD takes integer WE returns unit
return WE
return null
endfunction

function V9 takes unit R6 returns integer
return R6
return 0

function ZN takes unit TR,integer ZO,real S8,real ZP,real ZQ returns nothing
local unit u=TR
local unit e
if GetUnitAbilityLevel(u,'A07E')==0 then
call UnitAddAbility(u,'A07E')
endif
loop
exitwhen GetUnitUserData(u)==0
exitwhen WD(GetUnitUserData(u))==null
set u=WD(GetUnitUserData(u))
endloop
set e=CreateUnit(GetOwningPlayer(TR),ZO,GetUnitX(TR)+ZP,GetUnitY(TR)+ZQ,S8)
call SetUnitPathing(e,false)
call SetUnitX(e,GetUnitX(TR)+ZP)
call SetUnitY(e,GetUnitY(TR)+ZQ)
call SetUnitUserData(u,V9(e))
endfunction
 
I'd recommend reading this tutorial:

Those old maps typically took advantage of the return bug (which allowed you to typecast from one type to another, e.g. IDs to objects and vice-versa). For example, the WD function is likely I2U (Handle ID to Unit). The V9 function is likely U2I (Unit to Handle ID). So for example, if you took the functions from that thread, you could adapt the functions accordingly:
JASS:
globals
    hashtable MyHash = InitHashtable()
endglobals

function Unit2Int takes unit u returns integer
    return GetHandleId(h)
endfunction

function Int2Unit takes integer i returns unit
    call SaveFogStateHandle(MyHash,0,0,ConvertFogState(i))
    return LoadUnitHandle(MyHash,0,0)
endfunction

function WD takes integer WE returns unit
    return Int2Unit(WE)
endfunction

function V9 takes unit R6 returns integer
    return Unit2Int(R6)
endfunction
 
Level 1
Joined
Jan 2, 2024
Messages
2
I'd recommend reading this tutorial:

Those old maps typically took advantage of the return bug (which allowed you to typecast from one type to another, e.g. IDs to objects and vice-versa). For example, the WD function is likely I2U (Handle ID to Unit). The V9 function is likely U2I (Unit to Handle ID). So for example, if you took the functions from that thread, you could adapt the functions accordingly:
JASS:
globals
    hashtable MyHash = InitHashtable()
endglobals

function Unit2Int takes unit u returns integer
    return GetHandleId(h)
endfunction

function Int2Unit takes integer i returns unit
    call SaveFogStateHandle(MyHash,0,0,ConvertFogState(i))
    return LoadUnitHandle(MyHash,0,0)
endfunction

function WD takes integer WE returns unit
    return Int2Unit(WE)
endfunction

function V9 takes unit R6 returns integer
    return Unit2Int(R6)
endfunction
That's an amazing post! I somehow found a million other posts instead of yours.

And patching I2U indeed fixed the map for me. Now I can enjoy some good ol' CF with my hommies. Thank you!
 
Top