• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] is this correct?

Status
Not open for further replies.

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
Hi,
i am not very used to return function,
the only thing i know how to return is boolean.
so here there is a function wich take a force and return an integer, i want to know if i can call it and use it like that?

[Jass=]
function pickPlayer takes force team returns integer
local integer i = 0
loop
exitwhen i > 11
if IsPlayerInForce(Player(i), team) == true then
return i
endif
set i = i + 1
endloop
return 12
endfunction

function Totem_Timer takes nothing returns nothing
local real x
local real y
local integer i = 1
local integer p
set udg_TimerCheck = false
call DestroyTrigger( gg_trg_Totem_Timer_Remover )
call PauseTimer( udg_Totem_timer )
call DestroyTimerDialog( udg_Totem_window )
loop
exitwhen i > 12
if GetUnitState( udg_Hero_Building, UNIT_STATE_LIFE ) > 0.00 then
call SetPlayerState( Player(i-1), PLAYER_STATE_RESOURCE_GOLD, 1000 )
call IssueNeutralImmediateOrderById( Player(i-1), udg_Hero_Building[udg_A], 'H001' )
endif
set i = i + 1
endloop
set i = 1
loop
exitwhen i > 3
if udg_TeamNumber > 0 then
if udg_TotemOwned == false then
if GetWidgetLife(udg_TotemKit) > 0 then
call RemoveItem( udg_TotemKit )
set x = GetRectCenterX(udg_TeamStart)
set y = GetRectCenterY(udg_TeamStart)
set p = pickPlayer(udg_Team)
set udg_Totem = CreateUnit( Player(p), 'h004', x, y, bj_UNIT_FACING )
set udg_TotemOwned = true
endif
endif
else
set x = GetRectCenterX(udg_TeamStart)
set y = GetRectCenterY(udg_TeamStart)
set udg_Totem = CreateUnit( Player(PLAYER_NEUTRAL_PASSIVE), 'h004', x, y, bj_UNIT_FACING )
call KillUnit( udg_Totem )
endif
set i = i + 1
endloop
call TriggerSleepAction( 1.00 )
call DestroyTrigger( GetTriggeringTrigger() )
endfunction

//===========================================================================
function InitTrig_Totem_Timer takes nothing returns nothing
set gg_trg_Totem_Timer = CreateTrigger( )
call TriggerRegisterTimerExpireEvent( gg_trg_Totem_Timer, udg_Totem_timer )
call TriggerAddAction( gg_trg_Totem_Timer, function Totem_Timer )
endfunction
[/code]

i wanted to return a player at first but it looked too complicated...
 
Seems fine to me from what you explained what you wanted to see as to be correct. Although instead of storing the player integer into a variable, you can put the function call strait into the native.
JASS:
    set p = pickPlayer(udg_Team[i])
    set udg_Totem[i] = CreateUnit(Player(p), 'h004', x, y, bj_UNIT_FACING)
JASS:
    set udg_Totem[i] = CreateUnit(Player(pickPlayer(udg_Team[i])), 'h004', x, y, 270)
You could also do the same with the x and y variable as you are only using it on one other function.
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
not IsUnitType(udg_Hero_Building, UNIT_TYPE_DEAD)

is it really safe to use this?

anyway thanks everyone...
i need to test more but it works i think.
at least it compile and i didn't see anything wrong in game.
since you say the code look fine i am reassured.
 
Level 14
Joined
Jun 27, 2008
Messages
1,325
afaik this
JASS:
GetUnitState( udg_Hero_Building[i], UNIT_STATE_LIFE ) > 0.00
can cause bugs, because it is possible to change a dead units hp to something higher than 0.

Not sure about the UNIT_TYPE_DEAD solution, but i heard there are problems too...
 
Level 14
Joined
Jun 27, 2008
Messages
1,325
hum...
so i just need to change it to > 0.5 ?

NO, dou even read my posts?
afaik this
JASS:
GetUnitState( udg_Hero_Building[i], UNIT_STATE_LIFE ) > 0.00
can cause bugs, because it is possible to change a dead units hp to something higher than 0.

Not sure about the UNIT_TYPE_DEAD solution, but i heard there are problems too...


this still applies

(gawd i love quoting myself :eekani:)
It is possible to have a dead unit with 700 hp! Your "GetUnitState(...) > 0.405" wont work in that case.
(QUOTECEPTION \o/)

i would change it to this

JASS:
if not IsUnitType(udg_Hero_Building[i], UNIT_TYPE_DEAD) then
like maker suggested
Do this.
Or use a combination of both approaches.

A third approach would be "GetWidgetLife(udg_Hero_Building) > 0.405" which has the same problems (see my Quoteception) as "GetUnitState(...) > 0.405" but is slightly faster.
 
Status
Not open for further replies.
Top