Many BGL graphics commands have all the information required within the command itself. For example, the SPNT command only requires three arguments— x, y, and z, and these arguments are included as simple numbers in the command. These "self-contained" commands in BGL are similar to computer language instructions that use immediate mode addressing. However, like other computer languages, BGL contains commands and addressing modes that enable you to address and access variables. The following example includes the SETWRD command, which writes to a variable.
SETWRDcrash_flag,14
In the preceding example, the SETWRD command assigns the value 14 to the variable crash_flag. The crash_flag variable is a global variable in Flight Simulator. The following example shows the settings you can use for crash_flag.
ENUM16crash_flag;// crash monitor word
// 0 = no crash
// 2 = mountain crash
// 4 = general crash
// 6 = building crash (based on eye position)
// 8 = splash
// 10 = gear up
// 12 = overstress - break apart
// 14 = building crash (based on plane position)
// 16 = Aircraft Collision
// 18 = Fuel Truck Collision
// 20 = Object Collision
When the SETWRD command is executed by the BGL graphics interpreter, the variable crash_flag is set to 14, indicating that the plane has crashed into a building. Other Flight Simulator systems (sound, panels, and so on) examine this variable and react to the aircraft crash.
The following example, illustrates the VSCALE command. It’s important to understand everything shown in this example. Notice that the command format is similar to the SCALE command, with an important exception. Instead of submitting the lat/lon/alt as three 48-bit immediate constants, a pointer to a LATLONALT record is submitted. The pointer is a word offset into Flight Simulator's global variables.
typedef structSIF48
{
UINT16pad;
UINT16f;
SINT32i;
} SIF48, *PSIF48, **PPSIF48;
typedef structANGL48
{
UINT16pad;
UINT16lo;
UINT32hi;
} ANGL48, *PANGL48, **PPANGL48;
// LatLonAlt - used to store a position in 3-D space
typedef structLATLONALT
{
SIF48lat;
ANGL48lon;
SIF48alt;
} LATLONALT, *PLATLONALT, **PPLATLONALT;
cloud_1_llaLATLONALT<>;cloud level 1 center
The VSCALE command format is as follows:
Command:VSCALE
Operation:Scale command from a variable
Bytes:16
Format:[word]opcode=4ch
[word]skip address (relative)
[word]to see from radius (in meters, 0 = ignored)
[word]object size redoes (in scale units, 0 = ignored)
[word]radsort entry ptr
[dword]scale factor (if negative, no biases present)
[word]ptr to LATLONALT (FS6 format)
The following example shows how the VSCALE command is used.
VSCALE@oflo_ignore,0,0,CLOUD_1_SCALE, (cloud_1_lla - local_base_ptr)
@oflo_ignorelabelword
This preceding example is from the cloud generation system. A cloud is a graphics object that isn't static; that is, it can move along in the world coordinate system. In the example, the variable pointer points to the variable being accessed, cloud_1_lla. The variable cloud_1_ lla isn't a single variable, but rather a structure of the type LATLONALT. This structure is controlled by the clouds generation system, which changes the lat, lon, and altitude fields as the clouds move through space. The structure definitions that define the lat, lon, alt structure defines the variables as three 64-bit fields.
Caution: Variables in general, and complex variable structures in particular, often have format changes from version to version of Flight Simulator. Relying on a specific version when manipulating variables using variable commands can have different results, depending on what version of Flight Simulator is running the scenery. However, in most cases, the BGL code in existing scenery is self-compensating and runs regardless of version.