One of the major problems with variables was that no variable ever left the scope of the script. A variable created or modified in one script could not be accessed by another script. Flags are global variables that can be used through multiple scripts. There are 256 (0~255) server flags and 256 (0~255) flags per player.
All flags are accessesd using their flag number. Work with flags using the GetFlag and SetFlag functions:
EXTERNAL FUNCTION GetFlag(FlagNum AS LONG) AS LONG = 77
EXTERNAL SUB SetFlag(FlagNum AS LONG, Value AS LONG) = 78
Notice that flags can only store and retrieve Longs.
This sample JOINGAME script keeps track of the server's player population using flag number 4:
SUB Main(Player AS LONG)
If GetPlayerStatus(Player) = 2 Then SetFlag(4, GetFlag(4) + 1)
PlayerMessage(Player, "Player Population: " + Str(GetFlag(4)), BrightCyan)
END SUB
Player flags are attached to the players, and retain their value if they leave the game or the server goes down. The functions for these are:
EXTERNAL FUNCTION GetPlayerFlag(Player AS LONG, FlagNum AS LONG) AS LONG = 79
EXTERNAL SUB SetPlayerFlag(Player AS LONG, FlagNum AS LONG, Value AS LONG) = 80
Maps and objects also have flags associated with them.
One of the newer additions to MBSL, INIs allow you to have a potentially unlimited amount of storage space for both Longs and Strings.
INIs are stored in a file like this:
(Filename.ini)
[Header]
Name=Data
Name=Data
You can edit the data in an INI just by opening the file because of the simple and easy-to-read format.
The Header is mostly a way of grouping variables; you might want to have one header for each player for instance, or for each map. Each header has multiple variables under it, each with a unique Name.
INIs use the following MBSC functions:
EXTERNAL FUNCTION ReadiniInt(Filename As string, Header As string, Name As string, Default As long) AS LONG = 208
EXTERNAL FUNCTION ReadiniStr(Filename As string, Header As string, Name As string, Default As string) AS STRING = 209
EXTERNAL SUB WriteiniStr(Filename As string, Header As string, Name As string, Data As string) = 210