Tutorial Old LeaderLog - LaughingLeader-DOS2-Mods/LeaderLib GitHub Wiki
LeaderLib contains a collection of log functions that make the process of logging relatively simple.
The log command supports up to 12 strings:
Procedures:
LeaderLog_Log((STRING)_Type, (STRING)_Str1)
LeaderLog_Log((STRING)_Type, (STRING)_Str1, (STRING)_Str2)
LeaderLog_Log((STRING)_Type, (STRING)_Str1, (STRING)_Str2, (STRING)_Str3)
LeaderLog_Log((STRING)_Type, (STRING)_Str1, (STRING)_Str2, (STRING)_Str3, (STRING)_Str4)
LeaderLog_Log((STRING)_Type, (STRING)_Str1, (STRING)_Str2, (STRING)_Str3, (STRING)_Str4, (STRING)_Str5)
LeaderLog_Log((STRING)_Type, (STRING)_Str1, (STRING)_Str2, (STRING)_Str3, (STRING)_Str4, (STRING)_Str5, (STRING)_Str6)
//And so on...
Queries:
LeaderLog_QRY_Log((STRING)_Type, (STRING)_Str1)
LeaderLog_QRY_Log((STRING)_Type, (STRING)_Str1, (STRING)_Str2)
LeaderLog_QRY_Log((STRING)_Type, (STRING)_Str1, (STRING)_Str2, (STRING)_Str3)
LeaderLog_QRY_Log((STRING)_Type, (STRING)_Str1, (STRING)_Str2, (STRING)_Str3, (STRING)_Str4)
LeaderLog_QRY_Log((STRING)_Type, (STRING)_Str1, (STRING)_Str2, (STRING)_Str3, (STRING)_Str4, (STRING)_Str5)
LeaderLog_QRY_Log((STRING)_Type, (STRING)_Str1, (STRING)_Str2, (STRING)_Str3, (STRING)_Str4, (STRING)_Str5, (STRING)_Str6)
//And so on...
IF
TextEventSet("mymod_testrandom")
AND
LeaderLib_Random_QRY(1, 19)
AND
DB_LeaderLib_Temp_RandomResult(_Ran)
AND
IntegertoString(_Ran, _RanStr)
THEN
NOT DB_LeaderLib_Temp_RandomResult(_Ran);
LeaderLog_Log("DEBUG", "[MyMod:TextEventSet(mymod_testrandom)] LeaderLib_Random_QRY: | Result: [",_RanStr,"] | Min: [1], Max: [19]");
The _Type
parameter for LeaderLog_Log supports the following types:
Type | Description |
---|---|
DEBUG | The most common log type. Writes a message to the message log in the editor. |
TRACE | Similar to DEBUG, but traces are disabled by default, and enabled with the global flag "LeaderLog_Trace_Enabled". |
COMBINE | Used to combine strings into one, turning the log function into a more advanced StringConcatenate. |
COMBAT | Writes the message to the combat log via a target object. Limited to 255 characters (larger strings cause crashes!) |
STATUS | Displays the message as a status text on a target object. |
NOTIFICATION | Writes the message to a target player's notification panel (255 char limit!). |
Logging types "COMBAT", "STATUS", and "NOTIFICATION" require a target to work.
You can log a message to a target directly with:
LeaderLog_LogTarget((STRING)_Type, (GUIDSTRING)_Target, (STRING)_Str1)
LeaderLog_LogTarget((STRING)_Type, (GUIDSTRING)_Target, (STRING)_Str1, (STRING)_Str2)
LeaderLog_LogTarget((STRING)_Type, (GUIDSTRING)_Target, (STRING)_Str1, (STRING)_Str2, (STRING)_Str3)
//And so on...
LeaderLog_QRY_LogTarget((STRING)_Type, (GUIDSTRING)_Target, (STRING)_Str1)
LeaderLog_QRY_LogTarget((STRING)_Type, (GUIDSTRING)_Target, (STRING)_Str1, (STRING)_Str2)
LeaderLog_QRY_LogTarget((STRING)_Type, (GUIDSTRING)_Target, (STRING)_Str1, (STRING)_Str2, (STRING)_Str3)
//And so on...
Or set a general log target with:
LeaderLog_SetTarget
has the advantage of allowing multiple targets be set for the same message. Messages will keep displaying for the targets set until they are cleared.
LeaderLog_SetTarget((GUIDSTRING)_Target)
LeaderLog_QRY_SetTarget((GUIDSTRING)_Target)
Clearing targets:
LeaderLog_ClearTarget((GUIDSTRING)_Target)
LeaderLog_QRY_ClearTarget((GUIDSTRING)_Target)
LeaderLog_ClearAllTargets()
LeaderLog_QRY_ClearAllTargets()
Having to clear a target can be avoided by using the following proc/query to set a target:
LeaderLog_SetOneshotTarget((GUIDSTRING)_Target)
LeaderLog_QRY_SetOneshotTarget((GUIDSTRING)_Target)
LeaderLog_SetOneshotTarget
Automatically clears the target after a message is logged for that target.
Font color and size can be set for the next status log with the following:
LeaderLog_SetNextStatusColor((GUIDSTRING)_Target, (STRING)_Color)
LeaderLog_QRY_SetNextStatusColor((GUIDSTRING)_Target, (STRING)_Color)
LeaderLog_SetNextStatusColor((GUIDSTRING)_Target, (STRING)_Color, (STRING)_Size)
LeaderLog_QRY_SetNextStatusColor((GUIDSTRING)_Target, (STRING)_Color, (STRING)_Size)
These values are automatically cleared when the status log for that target is displayed.
IF
CharacterStatusAttempt(_Character, _Status, _Causee)
AND
String(_Causee, _CauseStr)
AND
CharacterGetDisplayName(_Character, _, _Name)
THEN
LeaderLog_Log("DEBUG", "[LeaderLib:Debug:CharacterStatusAttempt] Status [",_Status,"] attempt on character [",_Name,"] via cause [",_CauseStr,"].");
IF
ObjectFlagSet(_Flag, _Target, _DialogInstance)
AND
ObjectGetFlag(_Target, _Flag, _FlagVal)
AND
IntegertoString(_FlagVal, _FlagValStr)
THEN
LeaderLog_SetOneshotTarget(_Target);
LeaderLog_Log("COMBAT", "[LeaderLog:ObjectFlagSet] The flag [",_Flag,"] was set.");
IF
ObjectFlagCleared(_Flag, _Target, _DialogInstance)
THEN
LeaderLog_SetOneshotTarget(_Target);
LeaderLog_SetNextStatusColor(_Target, "#87CEEB", "26");
LeaderLog_Log("STATUS", "[LeaderLog:ObjectFlagCleared] The flag [",_Flag,"] was cleared.");
Using the LeaderLog for combining strings is a great way to avoid a mess of StringConcatenate queries:
PROC
MyMod_LaunchSkillTimer((CHARACTERGUID)_Player, (STRING)_Skill, (INTEGER)_Delay)
AND
NOT DB_MyMod_SkillTimers(_Player, _Skill, _)
AND
GetUUID(_Player, _UUID)
AND
LeaderLog_QRY_Log("COMBINE", "MyMod_Timers_", _Skill, "_", _UUID)
AND
DB_LeaderLog_Temp_CombinedString(_TimerName)
THEN
NOT DB_LeaderLog_Temp_CombinedString(_TimerName);
DB_MyMod_SkillTimers(_Player, _Skill, _TimerName);
TimerLaunch(_TimerName, _Delay);
Be sure to clear your DB_LeaderLog_Temp_CombinedString
entry, to keep the database tidy and lean.
Osiris lacks a way to convert real (float) numbers to strings, besides converting them to integers, which lacks precision. LeaderLib provides a way to trace real numbers:
LeaderLog_RealToString((REAL)_Num)
LeaderLog_QRY_RealToString((REAL)_Num)
LeaderLog_RealToString((REAL)_Num, (STRING)_CompletionEvent)
LeaderLog_QRY_RealToString((REAL)_Num, (STRING)_CompletionEvent)
LeaderLog_RealToString((GUIDSTRING)_Target, (REAL)_Num, (STRING)_CompletionEvent)
LeaderLog_QRY_RealToString((GUIDSTRING)_Target, (REAL)_Num, (STRING)_CompletionEvent)
If _CompletionEvent
is set, that event is called after the real is converted, which will allow you to get the value from the object passed in to the event, from the variable called: "LeaderLog_RealString"
.
Here, we convert the result of LeaderLib's sine function to a string:
IF
StoryEvent(, "LeaderLib_Initialized")
AND
GlobalGetFlag("LeaderLib_IsEditorMode", 1)
THEN
LeaderLib_Math_Sine(131.0);
IF
DB_LeaderLib_Math_Sine(131.0, _Result)
THEN
LeaderLog_RealToString(_Result, "LeaderLib_Events_Debug_SineResultConverted");
IF
StoryEvent(_Object, "LeaderLib_Events_Debug_SineResultConverted")
AND
GetVarString(_Object, "LeaderLog_RealString", _RealStr)
THEN
LeaderLog_Log("DEBUG", "[LeaderLib:Debug:Math] Sine | Angle [131] = [",_RealStr,"]");