Hibakeresés: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 6: Line 6:
* 2: errors and warnings
* 2: errors and warnings
* 3: errors, warnings and infos
* 3: errors, warnings and infos
Thus, by typing ''debugscript 3'' all messages are visible, that or level 2 are recommended for most occasions. You should have debugscript enabled most of the time you are testing your script.
Thus, by typing ''debugscript 3'' all messages are visible, that or level 2 are recommended for most occasions. You should have debugscript enabled most of the time you are testing your script, this will help you to detect typos or other simple to solve errors easily.
 
For example this snippet has two errors:
<syntaxhighlight lang="lua">
if (getClientName(player) == "Fedor")
outputChatbox("DISGRACE")
end
</syntaxhighlight>
 
==Debug strategies==
==Debug strategies==
There are several strategies that support finding errors, apart from going through the code of course. Most of them include outputting debug messages, with differing information depending on the situtation.
There are several strategies that support finding errors, apart from going through the code of course. Most of them include outputting debug messages, with differing information depending on the situtation.

Revision as of 23:26, 4 August 2007

While scripting you will often come across problems that are not immediately apparant. This page tries to point out some basic strategies to locate the error.

Debug console

MTA features a built-in debug console that shows debug messages created by MTA or the scripter. You can open it with by typing debugscript x in console, while x is the debug level:

  • 1: only errors
  • 2: errors and warnings
  • 3: errors, warnings and infos

Thus, by typing debugscript 3 all messages are visible, that or level 2 are recommended for most occasions. You should have debugscript enabled most of the time you are testing your script, this will help you to detect typos or other simple to solve errors easily.

For example this snippet has two errors:

if (getClientName(player) == "Fedor")
	outputChatbox("DISGRACE")
end

Debug strategies

There are several strategies that support finding errors, apart from going through the code of course. Most of them include outputting debug messages, with differing information depending on the situtation.