env#
env contains basic logging functions useful for debugging mission scripts. Logged
text is automatically written to dcs.log in the user’s Saved Games folder
(default location: C:\Users\<userName>\Saved Games\DCS\Logs).
Functions#
- env.info(message, showMessageBox)#
Logs
messageat INFO level. IfshowMessageBoxis true, also displays the message in a popup dialog.- Parameters:
message (
string) – Text to log.showMessageBox (
boolean) – Optional; show the message in a popup dialog.
Example:
env.info('Mission initialization complete.')
- env.warning(message, showMessageBox)#
Logs
messageat WARNING level. IfshowMessageBoxis true, also displays the message in a popup dialog.- Parameters:
message (
string) – Text to log.showMessageBox (
boolean) – Optional; show the message in a popup dialog.
Example:
env.warning('Group not found, skipping.', false)
- env.error(message, showMessageBox)#
Logs
messageat ERROR level. IfshowMessageBoxis true, also displays the message in a popup dialog.- Parameters:
message (
string) – Text to log.showMessageBox (
boolean) – Optional; show the message in a popup dialog.
Example:
env.error('Failed to spawn group.', true)
- env.setErrorMessageBoxEnabled(enabled)#
Enables or disables the automatic popup dialog that is normally shown when a Lua error occurs.
- Parameters:
enabled (
boolean) – Whether the error popup should be shown.
Example:
env.setErrorMessageBoxEnabled(false)
- env.getValueDictByKey(key)#
Looks up a localized string from the mission’s dictionary by key.
- Parameters:
key (
string) – Dictionary key to look up.- Returns:
The localized string, or
nilif not found.- Return type:
string
Example:
local text = env.getValueDictByKey('DictKey_ActionText_1')
Log format#
Log entries appear in dcs.log in the following format:
00104.229 INFO SCRIPTING: 'message'
Where the first column is the simulation timestamp, followed by the log level, the source of the log entry, and the logged data.
Other data#
The current mission’s mission and warehouse tables are also accessible via:
env.missionenv.warehouses
Footnotes#
Lua syntax errors are automatically logged to
dcs.logwithout requiring an explicit call toenv.error.