OutputDebugString: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Remove new item template.)
 
(13 intermediate revisions by 10 users not shown)
Line 1: Line 1:
__NOTOC__  
{{Server client function}}
__NOTOC__
This function outputs scripting debug messages, which can be read by enabling the debug textbox. The debug display level can then be set so that info or warning messages get filtered out.
This function outputs scripting debug messages, which can be read by enabling the debug textbox. The debug display level can then be set so that info or warning messages get filtered out.


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool outputDebugString ( string text, [ int level=3, int red, int green, int blue ] )             
bool outputDebugString ( string text, [ int level=3, int red=255, int green=255, int blue=255 ] )             
</syntaxhighlight>  
</syntaxhighlight>  


Line 13: Line 14:
{{OptionalArg}}  
{{OptionalArg}}  
*'''level:''' the debug message level. Possible values are:
*'''level:''' the debug message level. Possible values are:
**'''0:''' Custom message
**'''0:''' Debug message
**'''1:''' Error message
**'''1:''' Error message
**'''2:''' Warning message
**'''2:''' Warning message
**'''3:''' Information message (default)
**'''3:''' Information message (default)
*'''red''': The amount of red in the color of the text. Default value is 255.
**'''4:''' Custom message (omits file path and line number)
*'''green''': The amount of green in the color of the text. Default value is 255.
*'''red:''' The amount of red in the color of the text. Default value is 255.
*'''blue''': The amount of blue in the color of the text. Default value is 255.  
*'''green:''' The amount of green in the color of the text. Default value is 255.
'''Note:''' Color values are only applied when debug level is 0.
*'''blue:''' The amount of blue in the color of the text. Default value is 255.  
{{Note|Color values are only applied when debug level is 0 or 4.}}


===Returns===
===Returns===
Line 26: Line 28:


==Example==  
==Example==  
<section name="Server" class="server" show="true">
This script notifies when its resource has been loaded using a debug message:
This script notifies when its resource has been loaded using a debug message:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addEventHandler( "onResourceStart", getRootElement(), "resourceStartNotify" )
function resourceStartNotify ( resourcename )
function resourceStartNotify ( resourcename )
--if the started resource is this one
-- if the started resource is this one
if ( resourcename == getThisResource() ) then
if ( resourcename == getThisResource() ) then
--send an info debug message as a notification
-- send an info debug message as a notification
outputDebugString ( "Resource "..resourcename.." loaded.", 3 )
outputDebugString ( "Resource " .. getResourceName(resourcename) .. " loaded." )
end
end
end
end
addEventHandler( "onResourceStart", root, resourceStartNotify )
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{Server functions}}
{{Server functions}}

Latest revision as of 15:29, 20 June 2024

This function outputs scripting debug messages, which can be read by enabling the debug textbox. The debug display level can then be set so that info or warning messages get filtered out.

Syntax

bool outputDebugString ( string text, [ int level=3, int red=255, int green=255, int blue=255 ] )             

Required Arguments

  • text: the text to be output to the debug box.

Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.

  • level: the debug message level. Possible values are:
    • 0: Debug message
    • 1: Error message
    • 2: Warning message
    • 3: Information message (default)
    • 4: Custom message (omits file path and line number)
  • red: The amount of red in the color of the text. Default value is 255.
  • green: The amount of green in the color of the text. Default value is 255.
  • blue: The amount of blue in the color of the text. Default value is 255.
[[{{{image}}}|link=|]] Note: Color values are only applied when debug level is 0 or 4.

Returns

Returns true if the debug message was successfully output, false if invalid arguments are specified.

Example

Click to collapse [-]
Server

This script notifies when its resource has been loaded using a debug message:

function resourceStartNotify ( resourcename )
	-- if the started resource is this one
	if ( resourcename == getThisResource() ) then
		-- send an info debug message as a notification
		outputDebugString ( "Resource " .. getResourceName(resourcename) .. " loaded." )
	end
end
addEventHandler( "onResourceStart", root, resourceStartNotify )

See Also