HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Why Does this Crash?

05-06-2006, 09:09 PM#1
paidan_fain
Collapse JASS:
function P2D takes string s returns destructable d
if (s == "11") then
        return gg_dest_B001_0241
endif
if (s == "12") then
        return gg_dest_B000_0242
endif
if (s == "13") then
        return gg_dest_B001_0243
endif
if (s == "14") then
        return gg_dest_B000_0244
endif
if (s == "15") then
        return gg_dest_B001_0245
endif
if (s == "16") then
        return gg_dest_B000_0246
endif
if (s == "17") then
        return gg_dest_B001_0247
endif
if (s == "18") then
        return gg_dest_B000_0248
endif
endfunction

When I save the code, it seems to crash on variables -maybe implying the return destructables do not exist. That makes no sense though because I know they are there. Some help ?

Edited by Blade.dk. Reason: Fixed to use the correct tags.
05-06-2006, 09:39 PM#2
Tim.
Collapse JASS:
function P2D takes string s returns destructable

You had a d at the end.
05-06-2006, 09:59 PM#3
paidan_fain
ugh - stab me. I thought i fixed that. Guess thats what happens when I don't organize long lists of code.
05-07-2006, 02:55 PM#4
blu_da_noob
You also need a default return value after the last endif, in case none of them are true. Return null in this case, I assume.
05-07-2006, 03:16 PM#5
shadow1500
Why are you using so many if statments.. you can just use one and then continue with elseif's, like this:
Collapse JASS:
function P2D takes string s returns destructable
if (s == "11") then
        return gg_dest_B001_0241
elseif (s == "12") then
        return gg_dest_B000_0242
elseif (s == "13") then
        return gg_dest_B001_0243
...
...
else
        return null
endif
endfunction
you can also remove the paranteses, they are not neccecary.