HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Function Calls.

02-09-2003, 07:16 PM#1
Aiursrage2k
Two triggers x and y, in trigger x there is a function z among many others, is it possible to calll function z from trigger y?
02-09-2003, 07:29 PM#2
DoctorDoom
You could use a run trigger x ignoring conditions action in trigger y. Then have function z at the top of trigger x and after z create an action "If condtions for x are true then skip remaining actions" I think is along the lines of what you mean.
02-09-2003, 08:18 PM#3
Aiursrage2k
Thats somewhat what I want to do, but in jass you can create a trigger and pass it parameters, such as z(1,2,3) I want to be able to call do this function from trigger y, but the actual function is contained in trigger x. The major idea is to build somewhat of a libary of functions and be able to call it anywhere within the map, similar to blizzard.j functions.
02-09-2003, 08:25 PM#4
Ari
As far as I can tell the answer is no. You'll get compile errors if you try to either have
a) 2 functions with the same name in different triggers or
b) a trigger calling a function that exists in a different trigger

I've been told but cannot confirm that if you're willing to screw around in the *.j file after compilation, you can force two triggers to be able to access the same function, but I cannot confirm, and besides which, this would neccessitate screwing around after every save.

In my map, this has been a HUGE issue, and I curse blizzard for not letting you easily make "utility" functions that are readily callable from other triggers. I've devised two workarounds though. First, you can have the same function, but with slightly different names in each trigger that uses it:

function movement_is_animal takes unit, returns bool
function attack_is_animal takes unit, returns bool

This is useful if you just have a small number of triggers using each function. In my case, though, I quickly discovered myself accumulating 6 or more versions of a function, which was a massive pain in the *** when I had to redo one of them. So instead, I created a pass/return system. I created a global variable called PassedInteger, and another called ReturnedInteger (and ditto for reals, units, etc). I then created a series of triggers which were designed to act as functions:

function is_animal takes nothing, returns nothing

if (unit[udg_PassedInteger] == knight) then
set udg_ReturnedBool = no
return
endif

if (unit[udg_PassedInteger] == kodo) then
set udg_ReturnedBool = yes
return
endif

endfunction

Now, when I need to in this case, determine whether or not a given unit is an animal, I have this code ("unit" is a unit array in this example, x is a local integer):

// want to see if unit[x] is an animal

set udg_PassedInteger = x
triggerexecute (gg_trg_Is_animal)

if (udg_ReturnedBool == yes) then [whatever]

So I'm sort of "passing" variables and "returning" them, but they're all globals. This is ok for fairly simple functions, though.

Let me know if that made sense.