HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Converting nothing to integer

05-28-2009, 01:18 AM#1
Deaod
Yes, this is possible. You can spawn data out of nowhere.

Collapse JASS:
function N2I takes nothing returns integer
    return
    return 0
endfunction

Problem currently is: no JASS parser allows that function, although WC3 parses it without error.

Also, can anyone explain to me where that integer is coming from? I suspect it reads a specific register of the CPU but im not too sure (if at all).
05-28-2009, 02:25 AM#2
MaD[Lion]
weird u really get an integer?, cus when return stands alone i think it just simply exit the function. maybe it returns the function pointer? haha
05-28-2009, 05:13 AM#3
azlier
True, that doesn't compile (or pass through Jass parsers, I should say), but this does.

Collapse JASS:
function Nothing takes nothing returns nothing
    return
    return
endfunction

function N2I takes nothing returns integer
    return Nothing()
    return 0
endfunction

For me, it returns 1049284 on the first display and 0 on all new displays.

EDIT: It seems to return the first available handle slot, but then returns 0 on next calls...

What means this does?
05-28-2009, 05:16 AM#4
Vexorian
Quote:
Originally Posted by azlier
True, that doesn't compile, but this does.

Collapse JASS:
function Nothing takes nothing returns nothing
    return
    return
endfunction

function N2I takes nothing returns integer
    return Nothing()
    return 0
endfunction

For me, it returns 1049284 on the first display and 0 on all new displays.
THAT compiles?

I guess it would return the top of the stack or a random register.
05-28-2009, 05:29 AM#5
azlier
It reacts differently to whatever was called before it. I happened to do some handle creation, and set a boolean to false.

If I move it after, say, a text message, it returns 0 no matter what.

Aye, it is rather unpredictable.

Jass is quite the little monster.

EDIT: No, wait! I cracked it! It returns whatever the last called function did. The text message returned nothing, so 0.

Here are my test functions:
Collapse JASS:
function Nothing takes nothing returns nothing
    return
    return
endfunction

function N2I takes nothing returns integer
    return Nothing()
    return 0
endfunction

function C2I takes code c returns integer
    return c
    return 0
endfunction

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

function TestFunc takes nothing returns integer
    return 1337
    return 1337
endfunction

Collapse JASS:
call CreateTrigger()
call BJDebugMsg("Value of nothing: " + I2S(N2I()))
call BJDebugMsg("Value of new handle: " + I2S(H2I(CreateGroup())))
call TestFunc()
call BJDebugMsg("Value of nothing: " + I2S(N2I()))
call BJDebugMsg("Code value of nothing: " + I2S(C2I(function Nothing)))
call BJDebugMsg("Code value of N2I: " + I2S(C2I(function N2I)))
05-28-2009, 07:38 AM#6
PipeDream
There's a bytecode for setting the return value which only occurs before the return opcode if you return a value. It's actually a bytecode for copying one register to another, but the destination register is always 0, which isn't, as far as I remember, used for anything else.

Presumably this will go away in the next patch anyway.
05-28-2009, 01:25 PM#7
Vexorian
Quote:
Presumably this will go away in the next patch anyway.
You have no idea... (ok, maybe YOU do)