C-GEN - Cannis Games Editing Network  
   
  
   
   
 
     
 
   
 

RA2/YR: Local Variables: What they are for and how to use them
by Concolor1 and CannisRabidus. Published: 4/18/03. Last update: 4/18/03.

Introduction

Red Alert2 and Yuri's Revenge maps can optionally be made to make use of local variables. These variables are used to let the game "remember" that an event has taken place, and to use that fact to cause a trigger to fire at a later time. Typically you would use them if you had multiple events that need to happen before the trigger fires.

Note that there is a difference between local and global variables. Local variables are flags that are set while a map is running, and those flags are cleared once the map is no longer running. Global variables are flags that are set while a map is running, but are also incorporated into a saved game. Globals are therefore designed to be used in single-player campaigns, so that an event that takes place in one mission can influence actions in later missions. While there are strong similarities between local and global variables, the use of globals is beyond the socpe of this tutorial and we will limit ourselves to the discussion of local variables only.

Local variables can be used successfully in both single-player missions and in multiplayer maps. Some restraint should be exercised in their use in multiplayer maps though, since a map is considered unfair when there are prizes or advantages available, but not all players are aware of them.

The example used here is one of the most common uses of local variables. In this case we are looking to use a trigger to create a goodie crate when 2 different buildings are destroyed. For this example, 3 triggers are needed; one to make the game realize that the first building is destroyed, the second to make the game realize the second building is destroyed, and the third to create the crate when both the first and second triggers have fired.

For the sake of brevity this tutorial will not dwell on every detail regarding the construction of the triggers in this example. It is assumed the reader already knows how to make working triggers -- our purpose here is to concentrate on local variables and how to use them.

 
   
 
   
 

Creating the Local Variables

Let's say you wish to spawn a money crate on a map when both of 2 pre-placed buildings are destroyed. For the purpose of this example we'll make both of these building Tesla Coils. The idea is, the crate won't appear until both Tesla Coils are destroyed - we don't want a crate to appear if only one is destroyed.

First things first: Create the local variables. In Final Alert2, with the map loaded, go to the Edit menu and click Local variables (Locals). A small dialog will open. Type a description of your first variable in the Description field - in this case, let's call it "Coil 1 Destroyed".

Now you should set the Preset value for this local. As mentioned in the introduction, locals are flags that are either "set" (on) or "cleared" (off). In this dialog you can preset the local to be on or off when the map first loads. A value of 0 is a cleared local, and a value of 1 is a set local. In this case, let's give the local a preset value of 0, since when the map loads, the building won't be destroyed yet.

The drop-down selection field on this dialog should now display: 0 Coil 1 Destroyed,0. The first zero refers to the number of this local on the map's [VariableNames] list, and the second number indicates that this local starts off cleared.

Repeat for the second local variable you must create. Choose 1 No Name from the drop-down list, and enter "Coil 2 Destroyed" in the Description field, and again give this local a Preset value of "0". When done the drop-down selection field should display 1 Coil 2 Destroyed,0.

Suppose you screwed up the creation of your locals and you want to delete them? Sadly there is no way to delete unwanted local variables in Final Alert2. Unused locals will do no harm, so you could just leave them there, but if you prefer to clean up unneeded stuff, then you can delete local variables manually, by editing your map in a text editor. Locals are listed in the map under the [VariableNames] section. If you have created your locals exactly as described above, your [VariableNames] section should look like this:

[VariableNames]
0=Coil 1 Destroyed,0
1=Coil 1 Destroyed,0
As you can see the format is very simple, using the typical numbered list which starts with 0, as is used by many other lists in the RA2/YR games. The description can be anything and really doesn't matter to the game at all. The final number after the comma is always either 0 or 1 and determines whether the local is set or clear. Manual editing is therefore very easy should you wish to manage your locals by text editing instead.

Now let's move on to setting up the triggers so we can put these variables to work.

 
   
 
   
 

Setting Up the Triggers

As stated above this tutorial assumes the reader already has some proficiency in making working triggers in RA2/YR, so we won't dwell on every trigger-making detail here. To review, we are going to need 3 triggers for this example: one for each of the two Tesla Coils, and a third to spawn the money crate. At this point in time you may as well place the three objects on the map that you will need to support this - the two Tesla Coil buildings, and a waypoint where you intend the money crate to appear.

Create a new trigger, of the type that only fires once. Set its event to one of the appropriate "destroyed objects" options - event #48 (destroyed by anything) is probably the best choice. Now set this trigger's action to influence one of the local variables. There are 2 trigger actions which control this: #56 (local set) and #57 (local clear). Since each of the locals are already starting out cleared, we want to use action #56 (local set). Once you have selected this action, you will see a parameter which sets which local you intend the trigger to set. Select the first of the 2 locals you created as the parameter.

Now clone this trigger, and edit the action parameter of this clone so it points to the other local variable you created.

Close the trigger editor and double-click on the first Tesla Coil building. Set the "attached tag" of this building to the tag of the first trigger. Repeat for the second Tesla Coil, but attach the second trigger's tag to this one. Now when the first Tesla Coil is destroyed, the first local will change from cleared to set; and when the second Telsa Coil is destroyed, the second local will change from cleared to set.

Setting these locals does nothing by itself - the locals are only valuable as something for the game to read to decide what to do next. That's why we need to make a third trigger.

So create that third trigger. This one will look for local variables as the trigger's events. As with actions, there are 2 trigger events to choose from: #36 (local is set) and #37 (local is clear). We want this trigger to fire when the locals have been set, so make the first event #36, and set the parameter to the first local you made. Create a second event for this trigger, again it will be event #36, but this time the parameter will be the second local you created. The reason we need 2 events is so the trigger will not fire unless both events have been satisfied. Therefore, this trigger will fire only when both locals have been set; which will not occur unless both Telsa Coils have been destroyed.

Wrap up this trigger by setting its action to spawn a crate. The parameter to create a money crate is "0", and the other parameter sets what waypoint to spawn the crate at - point this to the waypoint you created.

At this point all that's left to do is to test your work in the game.

 
   
 
   
 

Summary

The example above is a very simple use of local variables. You can make things much more complicated if you like. The same logic can apply for 20 Tesla Coils - you would just have to make 20 local variables and 20 triggers to go along with them. Also it is important to note that locals can be set and cleared and set again indefinitely - which can be used for repeating actions which require involved events to take place before they are repeated. It's impossible to cover all possible uses of local variables in any tutorial, since their uses are limited only by the mapmaker's imagination.

Just keep in mind that any time you want the game to "remember" is something is on or off, true or false - then local variables are the tool that will do it for you.

 
   
 
 
     
 
 
All content, files, images, etc., appearing on this website and all hosted websites, are copyright © 2002-2006 by Cannis Games Editing Network (C-GEN),
and/or if applicable, by the Owner(s) of said hosted website(s), and/or in the case of submitted material, by the Author(s) of that material.
No reproduction of any of the above is permitted for any reason unless express permission is given by the applicable Owner(s) and/or Author(s).
All trademarks appearing on this website are, and remain, the property of their respective owners.
This website is best viewed with Internet Explorer 5 or higher, at a resolution of 1024x768 or greater.