• 🏆 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!

How to have a trigger that you can register functions to?

Status
Not open for further replies.
Level 12
Joined
May 22, 2015
Messages
1,051
If I want to have, say, a damage detection system that registers functions and only checks the functions that are registered, how should I go about doing that? Ignore doing anything for damage detection, I just want to be able to register functions to a trigger so that I am not duplicating events everywhere.

My current idea is to create triggers and manage an array of triggers. The damage system (or whatever other system) would then run all of the triggers when one of its events fires. The triggers that I add to the system will have no events. I am basically using them as function pointers.

I would use
JASS:
call TriggerEvaluate(trig)
since I have read that it is faster than
JASS:
call TriggerExecute(trig)
.

Is there a better way to do this or is this on the right track?

Note: I use default WC3 editor but I am using JASS for everything.
 

EdgeOfChaos

E

EdgeOfChaos

Couldn't you just add the function as an action for the trigger? That registers a function for it. Or am I misunderstanding you?
 
Level 12
Joined
May 22, 2015
Messages
1,051
The purpose is to not always have those functions in the trigger. If I have, say, a hero-specific damage detection effect (maybe like an aura that reduces damage taken), I don't want to always be checking for the aura buff to reduce the damage. If that specific hero is chosen, I add the function. Otherwise, I don't, so the damage detection trigger doesn't get super bloated.
 
You'll have a trigger and you can add conditions to it (allow the user to input code). See this for an example:
http://www.hiveworkshop.com/forums/jass-resources-412/system-track-205760/

If you want to pass data, you can just set globals (e.g. in onInteract in the system above). Note that there is a specific way to pass data to avoid any recursion issues. Let's say you want to pass some unit and an integer:
JASS:
/* Cache old values */
local unit temp = globalUnitData
local integer temp2 = globalIntData

/* Assign the data for this event */
set globalUnitData = <Some Unit>
set globalIntData = <Some Integer>

/* Fire trigger */
call TriggerEvaluate(EventTrigger)

/* Restore the data to the old values before the event fired */
set globalUnitData = temp
set globalIntData = temp2

set temp = null
 
Status
Not open for further replies.
Top