HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Reviving dead heroes (up to 11) with timers (jass) not working

02-07-2007, 09:50 PM#1
Mythic Fr0st
Ok, function Revive_Func0X20 runs, then checks if Unit has the item revitalize (I00N) the calls the function Revive_Func00A5, if it returns true (unit type of dying unit was equal to one of those heroes) and UnitHasItemOfType blah returns false
then it should do Func_1's actions, but it doesnt

Collapse JASS:
function Revive_Func00A5 takes nothing returns boolean
    return GetUnitTypeId(GetDyingUnit()) == 'H001'
    return GetUnitTypeId(GetDyingUnit()) == 'N00U'
    return GetUnitTypeId(GetDyingUnit()) == 'N00R'
    return GetUnitTypeId(GetDyingUnit()) == 'H002'
    return GetUnitTypeId(GetDyingUnit()) == 'E003'
    return GetUnitTypeId(GetDyingUnit()) == 'N01J'
endfunction

function Revive_Func0X20 takes nothing returns boolean
    return UnitHasItemOfTypeBJ(udg_Backpack_Unit[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))],'I00N') == false
    return Revive_Func00A5()
endfunction

function Func_1 takes nothing returns nothing
 local timer t = GetExpiredTimer()
 local location loc = GetRectCenter(gg_rct_Rect_035)
 local integer x = GetConvertedPlayerId(GetOwningPlayer(GetDyingUnit()))
    call ReviveHeroLoc(GetDyingUnit(), loc, false)
    call ShowUnitShow(udg_Backpack_Unit[x])
    call SetUnitPositionLoc(udg_Backpack_Unit[x], loc)
    call PanCameraToTimedLocForPlayer(GetOwningPlayer(GetDyingUnit()), loc, 0.00)
    call RemoveLocation(loc)
    set loc = null
    call DestroyTimerDialog(udg_TimerWind[x])
    call DestroyTimer(t)
    set t = null
    
endfunction

function Revive takes nothing returns nothing
 local timer t = CreateTimer()
 local integer x = GetConvertedPlayerId(GetOwningPlayer(GetDyingUnit()))
     call TimerStart(t, 23, false, function Func_1)
     call CreateTimerDialogBJ(t, GetPlayerName(GetOwningPlayer(GetDyingUnit())))
     set udg_TimerWind[x] = GetLastCreatedTimerDialogBJ()
     set t = null
     call ShowUnitHide(udg_Backpack_Unit[x])
endfunction

//===========================================================================
function InitTrig_Reviving_Heroes takes nothing returns nothing
    set gg_trg_Reviving_Heroes = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Reviving_Heroes, function Revive )
    call TriggerAddCondition(gg_trg_Reviving_Heroes,Condition(function Revive_Func0X20))
endfunction

if theyre are any leaks AT ALL tell me or anything i've done wrong
Is the correct, it should revive the hero (it needs to be able to be used up to 11 times at once, without messing things up)
02-07-2007, 10:08 PM#2
Alevice
Your first function would just stop at the first return. You can't just do it like that. You neeed conditional statements for that.

Collapse Probable alternative:
function Revive_Func00A5 takes nothing returns boolean
    local integer array unitType
    local integer i = 0
    set unitType[0] = 'H001'
    set unitType[1] = 'H001'
    set unitType[2] = 'N00U'
    set unitType[3] = 'N00R'
    set unitType[4] = 'H002'
    set unitType[5] = 'E003'
    set unitType[6] = 'N01J'
    
    loop 
        exitwhen i > 6
        if(GetUnitTypeId(GetDyingUnit()) == unitType[i]) then
            return true
        endif
    endloop
    return false
endfunction

Also, I suggest you to give your function more useful names; the one above could be called something like "IsUnitOfValidType" rather than "Revive_Func00A5".
02-07-2007, 10:11 PM#3
Vexorian
You can't GetDyingUnit on a timer expire event
02-07-2007, 10:18 PM#4
Mythic Fr0st
Ok, thanks, so you can only "return" one thing, then it ends?
02-07-2007, 10:23 PM#5
Alevice
Quote:
Originally Posted by Mythic Fr0st
Ok, thanks, so you can only "return" one thing, then it ends?
Whenever the function statement is reached, the function execution ends. With your original function, it would check GetUnitTypeId(GetDyingUnit()) == 'H001', if it isn't, just return false and end the execution. If jass had a "switch" or "select" statement, it would be a blessing.
02-07-2007, 10:23 PM#6
wyrmlord
Quote:
Originally Posted by Mythic Fr0st
Ok, function Revive_Func0X20 runs, then checks if Unit has the item revitalize (I00N) the calls the function Revive_Func00A5, if it returns true (unit type of dying unit was equal to one of those heroes) and UnitHasItemOfType blah returns false
then it should do Func_1's actions, but it doesnt

Collapse JASS:
//You're returning many values, you should only return 1
function Revive_Func00A5 takes nothing returns boolean
    return GetUnitTypeId(GetDyingUnit()) == 'H001'
    return GetUnitTypeId(GetDyingUnit()) == 'N00U'
    return GetUnitTypeId(GetDyingUnit()) == 'N00R'
    return GetUnitTypeId(GetDyingUnit()) == 'H002'
    return GetUnitTypeId(GetDyingUnit()) == 'E003'
    return GetUnitTypeId(GetDyingUnit()) == 'N01J'
endfunction

//You're returning two values, you should only return 1
function Revive_Func0X20 takes nothing returns boolean
    return UnitHasItemOfTypeBJ(udg_Backpack_Unit[PlayerId(GetOwningPlayer(GetTriggerUnit()))+1],'I00N') == false
    return Revive_Func00A5()
endfunction

function Func_1 takes nothing returns nothing
 local timer t = GetExpiredTimer()
 local location loc = GetRectCenter(gg_rct_Rect_035)
 local integer x = PlayerId(GetOwningPlayer(GetDyingUnit()))+1
    call ReviveHeroLoc(GetDyingUnit(), loc, false)
    call ShowUnit(udg_Backpack_Unit[x], true)
    call SetUnitPositionLoc(udg_Backpack_Unit[x], loc)
    call PanCameraToTimedLocForPlayer(GetOwningPlayer(GetDyingUnit()), loc, 0.00)
    call RemoveLocation(loc)
    set loc = null
    call DestroyTimerDialog(udg_TimerWind[x])
    call DestroyTimer(t)
    set t = null
    
endfunction

function Revive takes nothing returns nothing
 local timer t = CreateTimer()
 local integer x = PlayerId(GetOwningPlayer(GetDyingUnit()))+1
     call TimerStart(t, 23, false, function Func_1)
     set udg_TimerWind[x] = CreateTimerDialogBJ(t, GetPlayerName(GetOwningPlayer(GetDyingUnit())))
     set t = null
     call ShowUnit(udg_Backpack_Unit[x], false)
endfunction

//===========================================================================
function InitTrig_Reviving_Heroes takes nothing returns nothing
    set gg_trg_Reviving_Heroes = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Reviving_Heroes, function Revive )
    call TriggerAddCondition(gg_trg_Reviving_Heroes,Condition(function Revive_Func0X20))
endfunction

if theyre are any leaks AT ALL tell me or anything i've done wrong
Is the correct, it should revive the hero (it needs to be able to be used up to 11 times at once, without messing things up)

I'll take it that you're learning JASS. So far, not bad, but I'd like to point out some errors. The most obvious is that you're returning more than 1 value in both condition functions, only return 1. My guess is that you wanted to do something like:
Collapse JASS:
return <value> or <value> //Returns true if either condition is true
//Or possibly this
return <value> and <value> //Returns true if both are true, false otherwise
Also, you shouldn't refer to the dying unit in another function because it isn't reliable. Instead you should look into learning how to use gamecache. I've replaced some BJ function calls with native ones (only the really useless ones) and you're able to set a variable to a function call, you don't need to use GetLastCreated<object>. GetConvertedPlayerId returns PlayerId(player) + 1, iincase you were wondering.

Also, put the two functions used for conditions into one, there's no need for 2 functions.

EDIT: Wow, I took a long time to post, 4 posts while I was typing.
02-07-2007, 10:43 PM#7
Mythic Fr0st
Thanks,

Yes, im trying to learn the gamecache, I understand how it works, just dont have any knowledge about it apart from knowing how it works lol...

Why do I get a syntax error on every line with "Or" on it
And ALSO, how do I return the "item" check in the same condition!
Collapse JASS:
function Revive_Func0X20 takes nothing returns boolean
return GetUnitTypeId(GetTriggerUnit()) == 'H001' 
Or 
return GetUnitTypeId(GetTriggerUnit()) == 'N00U' 
Or 
return GetUnitTypeId(GetTriggerUnit()) == 'H002' 
Or 
return GetUnitTypeId(GetTriggerUnit()) == 'E003' 
Or 
return GetUnitTypeId(GetTriggerUnit()) == 'N01J' 
Or 
return GetUnitTypeId(GetTriggerUnit()) == 'N00R'

return UnitHasItemOfTypeBJ(udg_Backpack_Unit[GetPlayerId(GetOwningPlayer(GetTriggerUnit()))],'I00N') == false 
//(//HOW do I return this, without screwing the others up//)
endfunction

function Func_1 takes nothing returns nothing
 local timer t = GetExpiredTimer()
 local location loc = GetRectCenter(gg_rct_Rect_035)
 local integer x = GetPlayerId(GetOwningPlayer(GetTriggerUnit()))+1
    call ReviveHeroLoc(GetTriggerUnit(), loc, false)
    call ShowUnit(udg_Backpack_Unit[x], true)
    call SetUnitPositionLoc(udg_Backpack_Unit[x], loc)
    call PanCameraToTimedLocForPlayer(GetOwningPlayer(GetTriggerUnit()), loc, 0.00)
    call RemoveLocation(loc)
    set loc = null
    call DestroyTimerDialog(udg_TimerWind[x])
    call DestroyTimer(t)
    set t = null
    
endfunction

function Revive takes nothing returns nothing
 local timer t = CreateTimer()
 local integer x = GetPlayerId(GetOwningPlayer(GetTriggerUnit()))+1
     call TimerStart(t, 23, false, function Func_1)
     call CreateTimerDialogBJ(t, GetPlayerName(GetOwningPlayer(GetDyingUnit())))
     set udg_TimerWind[x] = CreateTimerDialogBJ(t, GetPlayerName(GetOwningPlayer(GetTriggerUnit())) + "'s Revive")
     set t = null
     call ShowUnitHide(udg_Backpack_Unit[x])
endfunction

//===========================================================================
function InitTrig_Reviving_Heroes takes nothing returns nothing
    set gg_trg_Reviving_Heroes = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Reviving_Heroes, function Revive )
    call TriggerAddCondition(gg_trg_Reviving_Heroes,Condition(function Revive_Func0X20))
endfunction

Any idea's
02-07-2007, 10:52 PM#8
wyrmlord
Here's how you'd use or (notice it's not capitalized)
Collapse JASS:
return GetUnitTypeId(unit) == 'A000' or GetUnitTypeId(unit) == 'A001'
My guess is that you want all the or conditons evaluated and then check to see if the unit also has the specific item? Do something like:
Collapse JASS:
 return (<condition> or <condition> or <condition>) and UnitHasItemOfTypeBJ(...)
02-07-2007, 10:53 PM#9
Alevice
As I said, you need if statements there, not return. Once a return is reached, the execution ends, no matter what. Also, it is 'or', not 'Or'.

Again,
Collapse JASS:
if (unitTypeofUnit=='x') or (unitTypeofUnit=='y') then
    return (unitHasItemType(myItemType)
    endif
endif

return false

wyrmlord method also works well, pick the one you feel the most comfortable with.
02-07-2007, 10:56 PM#10
Mythic Fr0st
Ok I realized I did something wrong, (didnt read properly)

Errors:
Syntax Error Line 2
Return Types not correct or non existant Line 3

Collapse JASS:
function Revive_Func0X20 takes nothing returns boolean
return (GetUnitTypeId(GetTriggerUnit()) == 'H001' or GetUnitTypeId(GetTriggerUnit()) == 'N00U' or GetUnitTypeId(GetTriggerUnit()) == 'H002' or GetUnitTypeId(GetTriggerUnit()) == 'E003' or GetUnitTypeId(GetTriggerUnit()) == 'N01J' or GetUnitTypeId(GetTriggerUnit()) == 'N00R') and UnitHasItemOfTypeBJ(udg_Backpack_Unit[GetPlayerId(GetOwningPlayer(GetTriggerUnit()))],'I00N') == false)
endfunction

function Func_1 takes nothing returns nothing
 local timer t = GetExpiredTimer()
 local location loc = GetRectCenter(gg_rct_Rect_035)
 local integer x = GetPlayerId(GetOwningPlayer(GetTriggerUnit()))+1
    call ReviveHeroLoc(GetTriggerUnit(), loc, false)
    call ShowUnit(udg_Backpack_Unit[x], true)
    call SetUnitPositionLoc(udg_Backpack_Unit[x], loc)
    call PanCameraToTimedLocForPlayer(GetOwningPlayer(GetTriggerUnit()), loc, 0.00)
    call RemoveLocation(loc)
    set loc = null
    call DestroyTimerDialog(udg_TimerWind[x])
    call DestroyTimer(t)
    set t = null
    
endfunction

function Revive takes nothing returns nothing
 local timer t = CreateTimer()
 local integer x = GetPlayerId(GetOwningPlayer(GetTriggerUnit()))+1
     call TimerStart(t, 23, false, function Func_1)
     call CreateTimerDialogBJ(t, GetPlayerName(GetOwningPlayer(GetDyingUnit())))
     set udg_TimerWind[x] = CreateTimerDialogBJ(t, GetPlayerName(GetOwningPlayer(GetTriggerUnit())) + "'s Revive")
     set t = null
     call ShowUnitHide(udg_Backpack_Unit[x])
endfunction

//===========================================================================
function InitTrig_Reviving_Heroes takes nothing returns nothing
    set gg_trg_Reviving_Heroes = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Reviving_Heroes, function Revive )
    call TriggerAddCondition(gg_trg_Reviving_Heroes,Condition(function Revive_Func0X20))
endfunction

Help me! im a jass bug lol
02-07-2007, 11:13 PM#11
Alevice
You DON'T write return again in the same sentence. Check carefully wyrmlord syntax.
And yes, you can adapt the first one I posted easily.

Just change return true to return UnitHasItemOfTypeBJ(udg_Backpack_Unit[GetPlayerId(GetOwningPlayer(GetTriggerUnit()))],'I00N') == false endfunction
02-07-2007, 11:15 PM#12
Mythic Fr0st
Yea I just realized as you posted -.- lol

but I still get errors

Just fixed it by retyping the code, thanks all


Code still didnt work though :(

CODE:

Collapse JASS:
function Revive_Func0X20 takes nothing returns boolean
return GetUnitTypeId(GetTriggerUnit()) == 'H001' or GetUnitTypeId(GetTriggerUnit()) == 'N00U' or GetUnitTypeId(GetTriggerUnit()) == 'H002' or GetUnitTypeId(GetTriggerUnit()) == 'E003' or GetUnitTypeId(GetTriggerUnit()) == 'N01J' or GetUnitTypeId(GetTriggerUnit()) == 'N00R' and UnitHasItemOfTypeBJ(udg_Backpack_Unit[GetPlayerId(GetOwningPlayer(GetTriggerUnit()))+1], 'I00N') == false 


endfunction

function Func_1 takes nothing returns nothing
 local timer t = GetExpiredTimer()
 local location loc = GetRectCenter(gg_rct_Rect_035)
 local integer x = GetPlayerId(GetOwningPlayer(GetTriggerUnit()))+1
    call ReviveHeroLoc(GetTriggerUnit(), loc, false)
    call ShowUnit(udg_Backpack_Unit[x], true)
    call SetUnitPositionLoc(udg_Backpack_Unit[x], loc)
    call PanCameraToTimedLocForPlayer(GetOwningPlayer(GetTriggerUnit()), loc, 0.00)
    call RemoveLocation(loc)
    set loc = null
    call DestroyTimerDialog(udg_TimerWind[x])
    call DestroyTimer(t)
    set t = null
    
endfunction

function Revive takes nothing returns nothing
 local timer t = CreateTimer()
 local integer x = GetPlayerId(GetOwningPlayer(GetTriggerUnit()))+1
     call TimerStart(t, 23, false, function Func_1)
     call CreateTimerDialogBJ(t, GetPlayerName(GetOwningPlayer(GetDyingUnit())))
     set udg_TimerWind[x] = CreateTimerDialogBJ(t, GetPlayerName(GetOwningPlayer(GetTriggerUnit())) + "'s Revive")
     set t = null
     call ShowUnitHide(udg_Backpack_Unit[x])
endfunction

//===========================================================================
function InitTrig_Reviving_Heroes takes nothing returns nothing
    set gg_trg_Reviving_Heroes = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Reviving_Heroes, function Revive )
    call TriggerAddCondition(gg_trg_Reviving_Heroes,Condition(function Revive_Func0X20))
endfunction
02-08-2007, 01:19 AM#13
Pyrogasm
Methinks GetPlayerId(GetOwningPlayer(GetTriggerUnit()))+1 should be GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))+1
That, and using some parenthesis would make the code look cleaner, like this: return (conditon 1 or condition 2 or condition 3) and (condition 4)
02-08-2007, 01:51 AM#14
Mythic Fr0st
Quote:
Methinks GetPlayerId(GetOwningPlayer(GetTriggerUnit()))+1 should be GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))+1
Nope

I was told by wyrm, to change

GetConvertedPlayerId, to change to GetPlayerId

He said "PlayerId" but there is no function PlayerId, so I figured he meant GetPlayerId

Parenthesis suck, lol they make me cry when they dont work

I'll try, though lol, thanks for trying to help ^_^
02-08-2007, 02:42 AM#15
wyrmlord
Quote:
Originally Posted by Pyrogasm
Methinks GetPlayerId(GetOwningPlayer(GetTriggerUnit()))+1 should be GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))+1
He originally was using GetConvertedPlayerId, and that returns GetPlayerId(...) + 1

Your code is fine in terms of syntax, right? I believe the problem now is that you need to use handle variable or gamecache in some way to keep track of heroes being revived. You can use either Kattana's handle variables or the CSCache and use either tables or attachable stuff (I don't use CSCache, but I have used the handle variables in the past and they're pretty simple).

Basically, which handle variables, using gamecache you're able to 'attach' information onto a handle, which in this case would be a timer. When the timer expires, you could refer to this info in order to get the dying hero and the timer dialog as well. I highly suggest using them.

If you wait long enough, I might finish lesson 8 in my JASS tutorial series (check signature), in which I might decide to use timers and handle variable or gamecache in some way. Your best bet would be just find the handle variables system and give it a shot at using them. If you have trouble, ask for help from someone.