Provide a reusable logging mechanism for playtest/debug sessions where events write short messages to a variable, and a central event group persists those messages to a run-specific log file.
This pattern is file-based logging:
FileSystem::LoadStringFromFileAsyncFileSystem::SaveStringToFileAsync
It does not use storage actions such as ReadStringFromStorage or
EcrireFichierTxt.
- Project-agnostic: no hardcoded scene names, object names, or state machine names.
- Scene-agnostic: can live in a shared external event, or in any scene.
- Low friction: any event can log by setting one variable.
- Traceable: one file per run, not one rolling file.
- First log write in a run creates a unique run id and file path.
- All later writes in the same run append to that same file.
- Log files are written under
documents/logs/. - Source control excludes generated log files.
Use either scene or global scope (choose once and stay consistent).
Debug_Log_String(string): message requested by gameplay/debug logic.Debug_Log_FilePath(string): current run log file path.Debug_Log_RunId(string): unique run identifier.
Optional helper variables:
Debug_Log_Timestamp(string): formatted time string.Debug_Log_HeaderWritten(boolean/number): guard for optional header.
Create one central event group (example name: Debug_Logging).
On scene start (or run start), clear:
Debug_Log_StringDebug_Log_FilePathDebug_Log_RunId
Conditions:
Debug_Log_Stringis not emptyDebug_Log_FilePathis empty
Actions:
- Build a run id from date/time plus random suffix.
- Set path:
documents/logs/run_<runId>.txt. - Optionally write a header line (
RunId, date/time, scene).
Condition:
Debug_Log_Stringis not empty
Actions:
- Build line:
[timestamp] <message>. - Append line to file (or read+concat+write if append is unavailable).
- Clear
Debug_Log_String.
Any event can write a log line by setting:
Debug_Log_String = "your message"
Prefer short, searchable prefixes, for example:
[ROOM] Enter pause[CAMERA] Snap to player[HAZARD] Activated
Use these as copy-safe patterns when building events in JSON.
Source evidence:
C:\GameDev\Dark-Ship-Codex\layouts\run.json:14829(FileSystem::SaveStringToFileAsync)C:\GameDev\Dark-Ship-Codex\layouts\run.json:14890(FileSystem::LoadStringFromFileAsync)C:\GameDev\Dark-Ship-Codex\layouts\run.json:14917(FileSystem::SaveStringToFileAsyncappend-via-rewrite)
Create file with initial header:
{
"type": { "value": "FileSystem::SaveStringToFileAsync" },
"parameters": [
"\"Log started: \" + Debug_Log_RunId",
"Debug_Log_FilePath",
"Debug_Log_Success"
]
}Load existing file content before appending:
{
"type": { "await": true, "value": "FileSystem::LoadStringFromFileAsync" },
"parameters": [
"Temp_Log_Content",
"Debug_Log_FilePath",
"",
""
]
}Append by rewriting full content:
{
"type": { "value": "FileSystem::SaveStringToFileAsync" },
"parameters": [
"Temp_Log_Content + NewLine() + Debug_Log_String",
"Debug_Log_FilePath",
"Debug_Log_Success"
]
}Observed project path builder:
{
"type": { "value": "SetStringVariable" },
"parameters": [
"Debug_Log_FilePath",
"=",
"\"C:/GameDev/Dark-Ship-Codex/documents/logs/\" + Debug_Log_RunId + \".txt\""
]
}Note:
- This project uses an absolute path expression for log files.
- For portability, prefer a project-relative pattern when possible (for example
documents/logs/run_<id>.txt).
Create folder and keep placeholder:
documents/logs/.gitkeep
Ignore generated logs:
documents/logs/*!documents/logs/.gitkeep
- Use scene variables when logs should reset per scene run.
- Use global variables when multiple scenes should write into one continuous run log.
- Keep all file I/O in one event group to avoid duplicate writes.
- Always clear
Debug_Log_Stringafter writing. - Avoid per-frame spam unless intentionally profiling.
- For high-frequency logs, gate writes behind a debug flag or sampled interval.
When applying this pattern to a different project, an AI should:
- Confirm whether variables should be scene or global.
- Add missing variables explicitly before referencing them.
- Create
documents/logs/and update ignore rules. - Keep the same variable names unless team conventions require renaming.
- Ensure only one logging event group performs file writes.