HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Passing variables from one trigger to another

06-14-2004, 05:15 PM#1
sATARa
Hello, Im quite new to JASS and I was wondering... how do you write a trigger that takes a unit variable from another trigger?
For an example:
I want trigger A to call trigger B, and pass it its triggering unit...
Could you plz write me an example of both triggers? I would really appriciate it...

p.s. First one to give me an good example gets a rep. point ^_^
06-14-2004, 05:32 PM#2
JTG
Code:
function testMain takes unit passedUnit returns nothing
	[size=2]call SetUnitLifePercentBJ( passedUnit, 1.00 )
[/size]endfunction

function test01 takes player whichPlayer returns nothing
	local unit unittopass = [size=2]CreateUnit(whichPlayer, 'hpea', 1200, 1200, 270)[/size]
[size=2]	call testMain(unittopass)
[/size]endfunction
tada
06-14-2004, 05:34 PM#3
PitzerMike
1. Possibility: A global variable

simply declare a unit variable Handover in the variable editor and there you go:
Code:
1. trigger:
set udg_Handover = GetTriggeringUnit()
call ExecuteTrigger(<trigger 2 here>)

2. trigger:

local unit U = udg_Handover


2. Possibility: Using game cache

might be too advanced for you if you are new to JASS, but if you like I can post a sample
06-14-2004, 07:14 PM#4
sATARa
Can I just make the trigger it self take parametars...
Prehaps Im the biggest newb on this forum, and what Im asking is really dumb, but if you have a trigger like this:
Code:
function Trig_Alcohol_effect takes nothing returns nothing
    call DisplayTextToForce( GetPlayersAll(), I2S(udg_ClubCelling) )
endfunction

//===========================================================================
function InitTrig_Alcohol_effect_Copy takes nothing returns nothing
    set gg_trg_Alcohol_effect_Copy = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Alcohol_effect_Copy, function Trig_Alcohol_effect_Copy_Actions )
endfunction

Whitch one of these "takes nothing" should I change so that the trigger takes a unit?
06-14-2004, 08:36 PM#5
AIAndy
Please use code tags instead of increasing the size. Since that really hurt the eyes I changed it for you.

On topic, where should the unit you want to pass to that trigger actually come from?
06-14-2004, 09:00 PM#6
sATARa
Quote:
Originally Posted by AIAndy
Please use code tags instead of increasing the size. Since that really hurt the eyes I changed it for you.

On topic, where should the unit you want to pass to that trigger actually come from?

It should be the triggering unit from another trigger...
06-14-2004, 09:17 PM#7
PitzerMike
* Functions used with TriggerAddAction can't have parameters, so you can't pass the unit into the second trigger without using global variables

* But I'd like to know why you even need a second trigger. From what I've seen you only execute it consequently after the first trigger finished, so you could also add the actions of the second trigger to the end of the first one
06-14-2004, 09:38 PM#8
sATARa
Quote:
Originally Posted by PitzerMike
* Functions used with TriggerAddAction can't have parameters, so you can't pass the unit into the second trigger without using global variables

* But I'd like to know why you even need a second trigger. From what I've seen you only execute it consequently after the first trigger finished, so you could also add the actions of the second trigger to the end of the first one

Yes, of course I can... but these triggers are huge, with lots of nested if statements, so I was just thiking of making it a bit easier to read.
But nevermind... I guess Ill do the thing I wanted to do, a bit differently.
Anyway, thx
06-14-2004, 11:32 PM#9
AIAndy
Then functions are the right way to go. Functions are executed in the context of the trigger from where they are called so Triggering Player is available there then.
06-15-2004, 04:58 PM#10
sATARa
Quote:
Originally Posted by AIAndy
Then functions are the right way to go. Functions are executed in the context of the trigger from where they are called so Triggering Player is available there then.

But I do need to write that function in the same trigger, right?
06-15-2004, 06:36 PM#11
PitzerMike
Quote:
Originally Posted by sATARa
But I do need to write that function in the same trigger, right?

Either in the same trigger or in the custom script header (when you click on the map name in the trigger editor).

For ordinary function calls you can also have parameters, although this won't be needed here since TriggeringUnit will still work in your sub-function.
06-16-2004, 10:45 AM#12
sATARa
Thx guys. This is a very good thing to know :D