HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Test

03-31-2008, 01:13 AM#1
Phish-Paste
Collapse JASS:
function DestroyUnit takes unit Die returns boolean //<< This takes a unit?
return IsUnitDead(Die) //<< This returns it's state
if Die = True then //<< This confirms it's state
call ReviveUnit(Die) // This revives the unit
else
endfunction

First off, I don't know a lot of JASS. I also know some of the strings I used aren't right, like call ReviveUnit() and the IsUnitDead() strings.

Anyway, in that function, if I did it right, should get a unit's state, and return it, then revive it if it's dead right?

What I need help with is how I would get that unit to be used in another function.

I know it has to do with the return bug, but I'm not sure what that is entirely.

Like say, I want to use that same unit and kill it later.
03-31-2008, 01:41 AM#2
Anitarf
First, your if statement lacks an endif line.
Second, after a function returns it no longer executes any code. In your case, it would never revive the unit.
Third, using indentation makes you code easier to read.
If you want to store a reference to a unit for later use, you use global variables.
03-31-2008, 01:48 AM#3
TheSecretArts
it should be
Collapse JASS:
function DestroyUnit takes unit Die returns unit
    if (IsUnitDead(Die)== true) then
        call ReviveUnit(Die)
    endif
    return (Die)
endfunction
03-31-2008, 09:47 PM#4
Themerion
Secretarts, I think you're getting him wrong. It said returns boolean... :/

Collapse JASS:
function MyOwnPwnFunction takes nothing returns unit
    return CreateUnit(Player(0),'hfoo',0,0,0)
endfunction

// loose code somewhere
// this must be below that which is above
udg_myUnit = MyOwnPwnFunction()
call KillUnit(udg_myUnit) // KillUnit might be leaking (it's no a big deal unless you have over 1000 units in your map). Read up on that somewhere else.