Lets say next we want to add a greet message whenever we go in the direction of location A to location B that looks like this:
To do so we can add a parameter to the ConnectRooms function. It's a good time to make use of a trick in Lua for optional parameters, this lets us add in a greet message from A to B, from B to A, or neither. Here's an example:
Code
ConnectRooms( "link's house a", "link's house b", "<13><1C>:: <4>Link's House <1C>::" )
The above line will generate triggers that displays a greet only going from A to B. We can add in another parameter for a message going from B to A (maybe saying that we are back in Hyrule):
Code
ConnectRooms( "link's house a", "link's house b", "<13><1C>:: <4>Link's House <1C>::", "<13><1C>:: <4>Hyrule <1C>::" )
It is easy to see the greet messages that I am using have some redundant text formatting. I can hide the text formatting inside of the ConnectRooms function, so long as I want the formatting to be the same for all greets (which I do):
Code
ConnectRooms( "link's house a", "link's house b", "Link's House", "Hyrule" )
The finished ConnectRooms function looks like:
Code
-- create the deathcounter variable with LIT
local roomDC = Deaths( )
roomDC:SetUnit( "Terran Physics Lab" )
roomDC:SetPlayer( 8 )
-- function that generates triggers to connect two locations
-- together to act as a doorway for a "hero unit" called LINK
function ConnectRooms( a, b, greetA, greetB )
-- move from a to b
p8:Conditions( )
roomDC:SetCount( 0 )
roomDC:Exactly( )
BringExactly( 1, LINK, a, 1 )
p8:Actions( )
roomDC:SetCount( 1 )
roomDC:SetTo( )
MoveUnit( 1, LINK, 1, a, b )
if greetA then Text( "<13><1C>:: <4>" .. greetA .. " <1C>::" ) end
Preserve( )
-- move from b to a
p8:Conditions( )
roomDC:SetCount( 0 )
roomDC:Exactly( )
BringExactly( 1, LINK, b, 1 )
p8:Actions( )
roomDC:SetCount( 1 )
roomDC:SetTo( )
MoveUnit( 1, LINK, 1, b, a )
if greetB then Text( "<13><1C>:: <4>" .. greetB .. " <1C>::" ) end
Preserve( )
-- turn off the DC when not present at a or b
p8:Conditions( )
BringExactly( 1, LINK, a, 0 )
BringExactly( 1, LINK, b, 0 )
roomDC:SetCount( 1 )
roomDC:Exactly( )
p8:Actions( )
roomDC:SetCount( 1 )
roomDC:SetTo( )
Preserve( )
end
local roomDC = Deaths( )
roomDC:SetUnit( "Terran Physics Lab" )
roomDC:SetPlayer( 8 )
-- function that generates triggers to connect two locations
-- together to act as a doorway for a "hero unit" called LINK
function ConnectRooms( a, b, greetA, greetB )
-- move from a to b
p8:Conditions( )
roomDC:SetCount( 0 )
roomDC:Exactly( )
BringExactly( 1, LINK, a, 1 )
p8:Actions( )
roomDC:SetCount( 1 )
roomDC:SetTo( )
MoveUnit( 1, LINK, 1, a, b )
if greetA then Text( "<13><1C>:: <4>" .. greetA .. " <1C>::" ) end
Preserve( )
-- move from b to a
p8:Conditions( )
roomDC:SetCount( 0 )
roomDC:Exactly( )
BringExactly( 1, LINK, b, 1 )
p8:Actions( )
roomDC:SetCount( 1 )
roomDC:SetTo( )
MoveUnit( 1, LINK, 1, b, a )
if greetB then Text( "<13><1C>:: <4>" .. greetB .. " <1C>::" ) end
Preserve( )
-- turn off the DC when not present at a or b
p8:Conditions( )
BringExactly( 1, LINK, a, 0 )
BringExactly( 1, LINK, b, 0 )
roomDC:SetCount( 1 )
roomDC:Exactly( )
p8:Actions( )
roomDC:SetCount( 1 )
roomDC:SetTo( )
Preserve( )
end
None.