BASIC VARIABLE USE (MAP MAKING)
Submitted by ArgCmdr
Variables are a basic programming concept, and are vital for event-action
characteristics. In fact, triggers on maps are based on variables, though
you cannot define them. For example, in a trigger you have an event that happens.
When this event happens the action fires. That "when this event happens" is
a variable. In a programming structure this would be:
IF
EVENT = N
DO ACTION
What
means that if event happening is N (the selected), the action fires. In this
case event is a variable, and if the variable is = N, the trigger fires.
The variables used in RA2 are Locals and Globals. Local variables take value
only during a misson/map. Globals, take their values through missions, so
if you do something in map 3, something differnet can happen in map 5. This
is usually used in TS, for the mission selection, as this disables the secondary
missions from the choosing map. In Ra2, this seems not to work on saves, though
it works fine normally. Meaning that if you play maps constantly and not save
and continue some other day, globals accomplish their function. If you save,
Global values (at least to my thinking) seem to take a temporal value that
is mantained during the level (NOT MISSION), that´s why this variables do
not mantain value through saves, cause this is the use they had in TS, their
default value restored after passing a level (not a mission, level was the
number of mission needed to be completed to access the next level with its
correspondant animation). My theory is based on facts, as i have tried globals
on saves with no results so far.
A variable in game is can have only two values, what they are called "boolean"
in programming: 0 or 1 (in fact, sometimes, anything different than 0), say
false and true, no and yes, bad and good, wrong and right. Set Variable means
add to variable a postive value. So if I (the variable) is = 0, then you can
ste it and that way the value go into 1. Clear Variable means go back value
of variable to 0. This are the only values available, as for event-actions
there are not multiple cases, its destroyed, or alive, is ok or wrong, same
boolean concept. In this case there are only two values, cause the probable
others (like captured, or infiltrated) are defined by the Entered by event,
and also when a building is captured it is considered destroyed. However variables
here can only be set to numbers, or at least its more secure. Different things
are statements in INI files, there specific parameters go to statements, some
boolean, but this ones usually are described by words.
To add a variable to a map you can make it by FA2 or a text editor (always
on the map file) In FA2: Go to Edit --> Local Variables Click on the first
undefined (if none is 0) on the deployable menu. Name it Set its initial value
(Depend on what u will use it for, if you have different concepts and want
in a mission that the player keeps alive a structure, set it to 1, (true,
alive), and then on the lose trigger set clear variable so that means a more
attractive logic, although its the same, there is no rational difference,
just affects the logic and thinking of the map-maker.
There are little base actions and events using local variables, but enough.
Events:
Local is Set (Makes the trigger fire when the variable´s value is true, or
equal to 1)
Parameter: The defined variable
Local Is Cleared (Makes the trigger fire when the variable´s value is false,
or 0)
Parameter: The defined variable
Actions: Set Local (Makes the variable change value to true or 1)
Parameter: The defined variable
Clear Local (Makes the variable change value to false or 0)
Parameter: The defined variable One of the multiple uses of this is on missions.
They are quite good to set multiple objectives to converge in a trigger, they
can also be used to spawn different triggers. In this case we will try to
make the player win when it has destroyed two specific factories. Point here
is that if you make the following trigger:
Name: Factories destroyed
Type: 0 (standard)
Tag : None
Event: Attached Object Destroyed
Parameter/s: The one/s u attach
Action: Win
You will get the fault than when one of the objects attached (When multiple,
if not the trigger works correctly) is destroyed the trigger fires. And player
wins when destroying just one building and not both. Variables get useful
here:
First define the variables setting the as follows:
Name:WF1
Initial Value: 0
Name:WF2
Initial Value: 0
Then make the triggers:
Name: Factory1
Type: 0
Tag: None
Owner: House that needs to destroy factory
Event: Attached Object Destroyed
Parameter: The attached object (WarFactory1)
NOTE:Remember
to attach the object to this trigger!!!
Action: Set Variable
Parameter: The variable you wanna set (In this case WF1)
Name: Factory2
Type: 0
Tag: None
Owner:House that needs to destroy factory
Event: Attached Object Destroyed
Parameter: The attached object (War Factory2)
NOTE:Remember to attach the object to this trigger!!!
Action: Set Variable
Parameter: The variable you wanna set (In this case WF2)
Name: Win
Type: 0
Tag: None
Owner: The house that wins when this events happen
Events:
1-Local is set (Parameter WF1)
2-Local is set (Parameter WF2)
Actions: 1-Win (Parameter, house of the winner)
This way player wins when destroys both factories and not one. As another
example, you can make the player lose when Tanya dies. This is much easier,
and as advice, doesn´t need variables at all (If you make a Attached object
destroyed (event)/ Lose (action), you get the same result with less work,
FA2 says this (variables) is a good way to make it, but much more time is
lost. Anyway its easy to explain, and you will proof if you understood:
Make a Variable called Tanya killed, initial value set to 0
Make a trigger standard, named Tanya is killed, with no tags and owned by
any house, easier if player or enemy as event does not say destroyed by.
Event: Destroyed by anything (so anyone)
Action: Set Variable "Tanya killed"
Open Tanya´s window and attach the tag of this trigger to the unit by selecting
it on the deployable menu on the proprties of the unit, and clicking on OK
Make a new trigger pointing, "lose (tanya dead)" as name, and the rest as
default, with the owner as the player.
Event: Variable Set, "Tanya Killed"
Action: Lose, Player House
If Tanya is not present on the map and comes by reinforcements, set the corresponding
tag on the teamtype instead of the unit properties (Properties of teamtype
instead of properties of unit). If Tanya is not alone in the team, you can
do several things depending on the way she appears, but always make a special
teamtype for her, and if you want the player to think it comes out of the
transport, while she is not on that team, you can create a team composed by
her, spwaned at the waypoint where the transport deploys, and using a sound
"Exit transport" so that it appears she was in, while she is not.
Another thing you can do and that is usually good looking is add a delay on
the lose trigger, so that you don´t lose inmediately and you get time to add
a text saying Tanya is dead, mission lost or similar. Very easy, just add
an action to the first described trigger, and use Enable Trigger (#53) and
as parameter set the other trigger related "lose (tanya dead)". Get that trigger
then, check the disabled box, and add a new event, elapsed time, and as parameter
the number of seconds you wish to pass between she dies and player gets lose
indicator.
As said, variables have several uses, like for example when X trucks have
unloaded their cargo. I think you can figure that out, you must set as many
variables as trucks in existance and set the variables whenever the corresponding
truck unloads its cargo. (This is tricky and invloves other map editing skils,
like scripts and celltag placing) But with this you are well covered.
>
Back to Tutorials