debug - MSUTeam/MSU GitHub Wiki
Note: This section is specifically about the mod-specific Debug system. For general utility logging features see Logging.
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.
It also allows mods to post messages to the MSU popup.
Every mod has a default flag that is passed to the debug functions.
This allows for simple syntax, such as <Mod>.printLog("text")
or if (<Mod>.Debug.isEnabled())
.
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 write
<Mod>.Debug.setFlag("ai", true)
in the definition of your mod. In the AI files, you would then use
<Mod>.Debug.printLog("My unit is thinking", "ai")
This will only print if the ai
flag is set to true.
All flags can be enabled or disabled at once via enable() and disable()
<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.
<Mod>.Debug.addPopupMessage( _text, _newState = ::MSU.Popup.State.Small )
// _text is a string containing the message you want to be posted within the popup
// _newState is a state from the ::MSU.Popup.State enum, either None (hidden), Small (small popup notification) or full (full size popup)
Posts a new message to the MSU popup. The info text of the small popup will be set to the mod ID of <Mod>
. The message consists of a header, with the mod name of <Mod>
, as well as the _text
below it.
This function can be used to inform the user of your mod about important things, such as potential errors, debug information and such, without the need for the user to check the log.
<Mod>.Debug.setFlag( _flagID, _flagBool )
// _flagID is a string
// _flagBool is a boolean
Sets (and creates if necessary) the flag _flag
to _flagBool
<Mod>.Debug.setFlags( _flagTable)
// _flagTable is a table of string : boolean entries
Calls setFlag(key, value)
on each entry in _flagTable
.
<Mod>.Debug.enable()
This sets all the debug flags to true. By default, this will only concern the default flag.
<Mod>.Debug.disable()
This sets all the debug flags to false. By default, this will only concern the default flag.
<Mod>.Debug.isEnabled( _flagID = "default" )
Returns true if debugging is enabled for _flagID
.
Returns false otherwise.
This can be used to enable further debugging tools.
For example, this could enable extra tooltips that the player is not supposed to see during normal gameplay.
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