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

Calling Functions from Another Trigger

Status
Not open for further replies.
Level 10
Joined
Feb 7, 2005
Messages
409
Ok, so, say I built multiple triggers that at points inside each trigger do the same thing.

Case In Point: My heroes can equip items, when they do, it sets animations, hero glows, and attachments based on the item.

Some abilities and death cause these to mess up, so in those cases it also sets animations, hero glows, and attachments.

Say I make a separate trigger (Z) that sets all the animations, hero glows, and attachments to a variable unit X

then in each trigger I set the triggering unit (buying, dying, casting) to unit X, run trigger Z, set udg_X = null.

Would this work? or would the multiple events clash / leak? Basically I want to put all the functions I would normally put in the same trigger in another trigger and call them using a set variable, then unsetting the variable after. This would cause the triggers to be smaller since instead of:

set attachment hand left = this one
set attachment hand right = this one
set attachment chest = this one
set attachment head = this one
set unit colour = this one

for every trigger it's just

set unit X = triggering unit
run trigger Z
set udg_X = null
 
Level 12
Joined
Dec 10, 2008
Messages
850
You can, but I think in GUI its alittle harder to pull off, since JASS is structured diffrently visually. Basicly, global variables, like udg_X, are set to that target until you either, set it null, set it to another unit, or set to no unit.

Your problem is that you set X null too fast, and it doesn't have the time to do the actions. Try nulling it in at the very end of the trigger Z were you attach the effects.
 
Level 10
Joined
Feb 7, 2005
Messages
409
Yeah I could do that, it's not that the trigger's not working persay, I was just wondering if it would cause leaks or could break at some point. The goal is really just to clean up some triggers that share the same functions you know? but in doing so I don't want to make it so those triggers are no longer MUI.
 
Level 8
Joined
Apr 30, 2009
Messages
338
As long as you don't have any waits it is fine since all the actions in the trigger takes place effectively instantaneously, but in order. It will not begin executing another trigger until the currently queued one is finished running. So from

set x = whatever
action 1
action 2
action 3
action 4
action 5
action 6
action 7
action 8
action 9
action 10
action 11
set x = null

as long as none of the actions allow time to elapse there is no way for x to be overwritten by another trigger.

I actually do something like this on my map, with a variable called current_hashtable. It just saves a lot of time so I can define current_hashtable at the start of a spell and refer to current_hashtable throughout the code instead of changing every hashtable argument for similar spells.
 
Status
Not open for further replies.
Top