OnDebugMessage: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "__NOTOC__ {{Server event}} This event is triggered when debug messages (for instance errors or warnings) appear in the server console. ==Parameters== <syntaxhighlight lang="lua"> string messa...")
 
m (Added example)
Line 23: Line 23:


==Example==  
==Example==  
This example outputs all debug messages to the chat box with the same colouring.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- TODO
addEventHandler("onDebugMessage", getRootElement(),
 
function(message, level, file, line)
 
if level == 1 then
outputChatBox("ERROR: " .. file .. ":" .. tostring(line) .. ", " .. message, getRootElement(), 255,0,0)
elseif level == 2 then
outputChatBox("WARNING: " .. file .. ":" .. tostring(line) .. ", " .. message, getRootElement(), 255,165,0)
else
outputChatBox("INFO: " .. file .. ":" .. tostring(line) .. ", " .. message, getRootElement(), 0,0,255)
end
 
 
end)
</syntaxhighlight>
</syntaxhighlight>


{{See also/Server event|Server events}}
{{See also/Server event|Server events}}
[[Category:Needs_Example]]

Revision as of 18:55, 28 February 2012

This event is triggered when debug messages (for instance errors or warnings) appear in the server console.

Parameters

string message, int level, string file, int line
  • message: The message which was outputted in the server console, without details like file, line etc
  • level: The type of debug message which was outputted
    • 0: "Custom" message
    • 1: Error message
    • 2: Warning message
    • 3: Information message
  • file: The file from which the debug message was outputted
    • Note: May return nil when the source could not be found
  • line: The line in file file where the debug message was outputted
    • Note: May return nil when the source could not be found

Source

The source of this event is the root element.

Example

This example outputs all debug messages to the chat box with the same colouring.

addEventHandler("onDebugMessage", getRootElement(), 

function(message, level, file, line)

if level == 1 then
	outputChatBox("ERROR: " .. file .. ":" .. tostring(line) .. ", " .. message, getRootElement(), 255,0,0)
elseif level == 2 then
	outputChatBox("WARNING: " .. file .. ":" .. tostring(line) .. ", " .. message, getRootElement(), 255,165,0)
else
	outputChatBox("INFO: " .. file .. ":" .. tostring(line) .. ", " .. message, getRootElement(), 0,0,255)
end


end)

See Also

Server events


Event functions