HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Why does this crash?

06-20-2004, 09:31 AM#1
R3N3G4D3
I needed a function to convert integer to boolean, and I wrote 1, but now everytime I try to save my map, the editor crashes when saving variables. Please tell me what's wrong with this:

function I2B takes integer a returns boolean
if a=0 then
return false
else
return true
endif
endfunction
06-20-2004, 01:16 PM#2
AIAndy
a == 0 instead of a = 0
06-20-2004, 03:29 PM#3
weaaddar
may I place a suggestion?
function I2B takes integer I returns boolean
return i
return false
endfunction

The return bug works between ints and booleans to, as far as I remember 0 is false and anything else is true.
06-20-2004, 07:15 PM#4
Luzif3r
do you really think we should rely on bugs? even if it works...
06-20-2004, 07:23 PM#5
R3N3G4D3
Thanks, it fixed it, and thanks for return bug suggestion, I didn't think of that.
Quote:
do you really think we should rely on bugs? even if it works...
It's not really a bug, just another way of tricking the editor not to complain about it. It's like NoLimits program, it just solves the issue with Editor refusing to save the map because of this. Besides, Cubasis said that Blizzard use return bug in their own maps too.
06-20-2004, 07:48 PM#6
AIAndy
There has been an official statement by Blizzard that the return bug will not be "fixed".
06-20-2004, 10:40 PM#7
Xinlitik
How exactly does the return bug work in functions like those?
06-20-2004, 11:05 PM#8
Cubasis
It just returns what the variable contains in the new format.

All types in WC3 are ... 32 bit.

Ints contain their value.
Reals contain their value using normal float standard.
Booleans contain their value as 0=false <everything-else>=true.
Strings contain a address to a certain String array where the specified string is stored.
Handle types contain a address to where it is stored in memory (well, not really, but where in the WC3 memory it is...or whatever). So you'll get a value like... 96000 or sumtin... if you return it as a integer.

So, as they are all 32-bit, we can fool the compiler/game to think that a integer is a boolean... or a location is a integer, and thus, we can f.ex. store a UnitGroup, as a integer (its address), in Game Cache.

And the way it works is that.... the compiler only checks/complains about the "last" return statement in a function. That's why we can return anything we want, just if we put a legit dummy-return statement at the end.

~Cubasis
06-21-2004, 02:23 AM#9
Xinlitik
I see..thank you. So then you just put that integer into a game cache and then take out the integer from game cache and convert it back to unit etc?