To make your code easier to understand and modify, I recommend to take a skim through the following guidelines:
Recommended coding design
When you are coding, it is recommend to indent (by using TAB or four spaces) lines as per the scope, see the example below.
Commenting your code
If you are releasing code to the community, then commenting the code is important in order for other users to understand your code. This is not particularly necessary on EVERY line, but lines that do not have an obvious outcome should be commented. Another reason of commenting your code is for organizing and separating code into categories/sections. See the example below for how to comment.
Commenting one line is more suited to putting the double dashes at the start of the sentence, however, if you would like to commenting a chunk of code, you only require to put a --[[ and ]]
Organizing your code
A shopping market has all that beer in the alcohol section, right? In coding MTA resources, to ensure the code is legible you should put certain components in the right order.
Event adding - using addEvent to allow calling of custom event handlers
Variables - defining PRESET variables, for example a table of language ID's or options
Functions - creating functions
Handlers - using addEventHandler, this should be right after the function
See the example below:
DONT GO CRAZY!
Don't make variables like reallycoolfeatureenablebooleanvalue for enabling a really cool feature that just is a boolean value. Instead you should use something short and to the point, for example instead of the aforementioned variable name, you could use enableCoolFeature.
Scripting logs
All debug lines (i.e INFO, WARNING, ERROR) are logged, saved into a specific file depending where the debug line was executed on the client or on the server
Server log: \deathmatch\logs\server.log (this may not be the case if you disable or modify this in the conf)
Client log: \MTA\clientscript.log
Periodically you should clear your log if you are interested in saving disk space
FINGER, MY CO E DOESNT WORK
If your code isn't working the way you wanted it to, use the /debugscript 3 command, some servers enable this for all users, however on most servers and default servers you are required to be an administrator(*?)
There are three types of errors:
ERROR
WARNING
INFO
Below are how debug messages are generally structured:
If the event you do NOT get any errors, you should check your code. For example, if the thing you want to do starts with a command. Go to the line containing the command, then go to its function and check each line for errors
If your resource still fails to work, you should check your meta.xml file, it is a possibility that your meta.xml has syntax errors or you didn't add your script to the file.
If you are tired or fed up of going into the game just to find another error, then a few 3rd party software are available, please note that these links may not parse and show errors in the functions, but only syntax code (missing parenthesis etc.)
Here is the list of software:
Notepad++ (use this if you are interested in something light, resourceful and supporting of multiple language)(recommended)
LuaEdit (use this if you are only interested in editing lua files)
MTA Script editor
(this was built for mta, has an IDE (integrated development environment) with autocompletion and other fancy features, its slightly outdated and buggy)
Where to go from here
The best ingame script editor (syntax checking, file editing, resource management and color coding): resedit
Multi Theft Auto Wiki:
Main Page
Scripting Introduction
Introduction to Scripting the GUI
Debugging
If you have any other guidelines for coding or tips don't hesitate to PM me and I will add your advice to this post!
(*?) = is this advice correct?