• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

[JASS] Conditions...and Conditions in Actions?

Status
Not open for further replies.
Level 2
Joined
Sep 21, 2005
Messages
27
I'm just curious which method would be faster - using the trigger's 'Conditions' function, or simply sticking the conditions in the 'Actions' function? This Trigger is going to be called a LOT, so speed is important.

Putting the conditions in the actions makes it so some local variables only have to be allocated once instead of twice, which also means one less call to GetTriggerUnit()

All opinions welcome! :D

Here's the code incase an expert is interested...though I've got a half dozen more scripts that integrate with it, so it doesn't appear complete.
JASS:
function Trig_Spot_Units_Actions takes nothing returns nothing
local unit myUnit = GetTriggerUnit()
local integer WaypointNum = R2I(GetUnitAcquireRange(myUnit))-49

if(GetPlayerId(GetOwningPlayer(myUnit)) == 10) and (RAbsBJ(GetUnitX(myUnit)-udg_PointIndexX[WaypointNum]) < 16) and (RAbsBJ(GetUnitY(myUnit)-udg_PointIndexY[WaypointNum]) < 16) then

	// Not at End
	if R2I(GetUnitAcquireRange(myUnit)) != (48+udg_PointCount) then
	call SetUnitAcquireRange(myUnit, GetUnitAcquireRange(myUnit)+1)
	call IssuePointOrder(myUnit, "move", udg_PointIndexX[WaypointNum +1], udg_PointIndexY[WaypointNum +1])
	
	// At End of Path
	else
	call ExplodeUnitBJ(myUnit)

	endif
endif

endfunction
 

//===========================================================================
function InitTrig_Spot_Units takes nothing returns nothing
call TriggerAddAction(CreateTrigger(), function Trig_Spot_Units_Actions)
endfunction
Thanks!
 
Level 7
Joined
May 6, 2005
Messages
390
Conditions is faster, for example it skips the declaration of locals used in the actions function, and spares some time thereby.
 
Level 7
Joined
May 6, 2005
Messages
390
yeah, ain't it?

But it wasn't my idea. Someone asked the same question at the Jass Vault some time ago, and someone came with this point.
 
Level 2
Joined
Sep 21, 2005
Messages
27
Blade.dk2 said:
Conditions is faster, for example it skips the declaration of locals used in the actions function, and spares some time thereby.

Well, I had a lengthy discussion with some people that know more about JASS than I do, and then I threw a test map together to check. It never skips declaration of variables, but it does entirely skip the 'actions' function if the conditions are not met.

All in all...just go with whatever method you want. It's too hard to measure how the size of the 'conditions' function vs the size of the 'actions' function impacts performance(when sometimes it will evaluate true and other times it will not :p ).
 
Level 7
Joined
May 6, 2005
Messages
390
I said it skipped declaration of locals in the actions function as it never will be runned if the condition returns false, read my post.
 
Level 2
Joined
Sep 21, 2005
Messages
27
Blade.dk2 said:
I said it skipped declaration of locals in the actions function as it never will be runned if the condition returns false, read my post.

And I told you that the locals would be initialized in both, in order to perform checks. Considering what I said, you were incorrect, but if you ignore what I said, then yes you were right.
 
Level 7
Joined
May 6, 2005
Messages
390
IF the condition returns false, no locals will be declared in the actions and how many conditions have locals? 1/500 or something, it's not like we want advanced actions in the condition, that would be lame.
 
Status
Not open for further replies.
Top