Using Constants

By HeliJunkie

What are constants?

Constants are a type of variable. You can give the constant a value, but you can't change the value later, while using the constants.

How can they help me?

I told you that every control type has a "type" property value. It's easier for a human to remember words we know rather than some numbers. So we create "speaking" constants, and use them later in the dialog definition. They also make our definition more readable. If I would ask you which control has a type number of "5", you normal can't answer me. If you read "CT_ListBox" you will have an idea of the control type.

Defining constants

To define a constant you have to use the following syntax:

#define Constantname ConstantvalueLet us build a simple to remember constant for our button. Let's use the prefix "CT_" for "control types". Then we extend the name with a control type name "Button".

#define CT_Button 1

In every line of code behind this definition the word "CT_Button" is replaced by 1 (from the game engine). So our file should now look like this:

#define CT_Button 1
//..
type = CT_Button;
And the game engine will read "type=1;".

Here are a lot of constants we should use, this is a list of constants that I use:

// Control types
#define CT_STATIC 0
#define CT_BUTTON 1
#define CT_EDIT 2
#define CT_SLIDER 3
#define CT_COMBO 4
#define CT_LISTBOX 5
#define CT_TOOLBOX 6
#define CT_CHECKBOXES 7
#define CT_PROGRESS 8
#define CT_HTML 9
#define CT_STATIC_SKEW 10
#define CT_ACTIVETEXT 11
#define CT_TREE 12
#define CT_STRUCTURED_TEXT 13
#define CT_CONTEXT_MENU 14
#define CT_CONTROLS_GROUP 15
#define CT_XKEYDESC 40
#define CT_XBUTTON 41
#define CT_XLISTBOX 42
#define CT_XSLIDER 43
#define CT_XCOMBO 44
#define CT_ANIMATED_TEXTURE 45
#define CT_OBJECT 80
#define CT_OBJECT_ZOOM 81
#define CT_OBJECT_CONTAINER 82
#define CT_OBJECT_CONT_ANIM 83
#define CT_LINEBREAK 98
#define CT_USER 99
#define CT_MAP 100
#define CT_MAP_MAIN 101
// Static styles
#define ST_LEFT 0x00
#define ST_RIGHT 0x01
#define ST_CENTER 0x02
#define ST_HPOS 0x03
#define ST_DOWN 0x04
#define ST_UP 0x08
#define ST_VCENTER 0x0c
#define ST_VPOS 0x0C
#define ST_POS 0x0F
#define ST_SINGLE 0x00
#define ST_MULTI 0x10
#define ST_TITLE_BAR 0x20
#define ST_PICTURE 0x30
#define ST_FRAME 0x40
#define ST_BACKGROUND 0x50
#define ST_GROUP_BOX 0x60
#define ST_GROUP_BOX2 0x70
#define ST_HUD_BACKGROUND 0x80
#define ST_TILE_PICTURE 0x90
#define ST_WITH_RECT 0xA0
#define ST_LINE 0xB0
#define ST_C 0xC0
#define ST_D 0xD0
#define ST_E 0xE0

As you can see there are a lot of control types. Some can't be used in Arma, (like the progressbar), but that is a list of constants that users all around the world have figured out from the OFP/Arma config files. The first block includes the control types. They all start with "CT_". The second block is mainly used to change the appearance of the static control (CT_Static). They all begin with "ST_" (Style). At least there some constants for the slider control ("SL_") and for the listbox control ("LB_"). These ST_ and LB_ are BI naming conventions and can be really named anything.