Skip to content
TaroEld edited this page Apr 14, 2022 · 16 revisions

MSU adds functionality to improve the debugging capabilites of the user. It allows the user to leave debugging information in the code, but turn off specific parts when distributing the mod.

Flags

Every mod has a default flag. This allows for simple syntax, such as <Mod>.printLog("text"). If you want more granularity, you can add further flags to turn debug on and off for specific areas of the mod. For example, you might want a flag to govern only AI-related events. You would .Debug.setFlag("ai", true in the definition of your mod. In the AI files, you would then use .Debug.printLog("My unit is thinking", "ai") . This will only print if the ai flag is set to true.

<Mod>.Debug.printLog( _printText, _flagID = null ) // printWarning/printError
// _printText and _flag ID are strings

Substitutes for this.logInfo, this.logWarning and this.logError
Print the log as _printText if debugging is enabled.
_flagID specifies a flag of the mod, and is set to default if left empty.

setFlag

<Mod>.Debug.setFlag( _flagID, _flagBool )
// _flagID is a string
// _flagBool is a boolean

Sets (and creates if necessary) the flag _flag to _flagBool

setFlags

<Mod>.Debug.setFlags( _flagTable, _flagTableBool = null )
// _flagTable is a table of string : boolean entries
// _flagTableBool is a boolean

Calls setFlag(key, value) on each entry in _flagTable.
If _flagTableBool is not null, calls setFlag(key, _flagTableBool) on each entry instead.

isEnabled

<Mod>.Debug.isEnabled( _flagID = "default" )

Returns true if debugging is enabled for _flagID.
Returns false otherwise.

Example

local yourmod = ::MSU.Class.Mod("yourmod", "1.0.0");
// we've now enabled the default flag for our mod so when we do
yourmod.Debug.printLog("Test");
// it will print to the log.
local newFlags = {
    flag1 = true,
    flag2 = false
}
// now we create a new flagTable
yourmod.Debug.setFlags(newFlags);
// and add it to our mod
yourmod.Debug.printWarning("Prints!", "flag1");
// this would still print because flag1 = true
yourmod.Debug.printError("Does not print!", "flag2");
// would not print because flag2 = false, but if we do
yourmod.Debug.setFlag("flag2", true);
yourmod.Debug.printError("Prints!", "flag2")
// this will now print to the log
Clone this wiki locally