Lou Montana/Sandbox – User
Debugging Techniques are ways in which developers can debug, or find out where errors or unexpected outcomes are occurring within their scripts. Several methods of debugging exist, however there is no debugging system as such available to developers similar to that which is found within an Integrated Development Environment or with other languages.
Code
Syntax Highlight
Syntax errors can be a frequent occurrence when developing scripts. Syntax highlight will help you find typos in commands
Squint provides a fully-featured code editor which allows for syntax highlighting, displaying of errors and code correction. A simpler solution of code highlighting for Notepad++ is also available, although errors will only be visible from the absence of highlighting. The plugin will automatically check if you are using all commands with the proper syntax and with proper argument types. Using SQDev you will get code validation (linting) while you are typing it.
Many tools are available:
- Sanjo's Notepad++ SQF (npp-sqf): Forum post - GitHub repository
- krzmbrzl's SQDev: Forum post - GitHub repository
- Sbsmac's Squint: Forum post - website
Finding Errors
To solve an issue, you must first find out there is one. Besides your script not having the wanted effect (if any), an error message helps you locate the code issue.
- Be sure to use -showScriptErrors startup parameter to display the error on-screen
- Read RPT files for more information (make sure -noLogs startup parameter is not enabled or the logs will never be filled)
- Scripts running on a server use the ArmaXServer.RPT file which has varying locations depending upon the type of server being run.
- Scripts running on a client use the ArmaX.RPT file.
- RPT files location is usualle %localappdata%\ArmaX
Removing Errors
Once the script error is located: 'be sure to check the BiKi page corresponding to the command/function you are using!!
Common errors
- If a generic error happens on a sleep/uiSleep/waitUntil, you may be in unscheduled environment
Working with Addons
If you are working on an addon, repacking a PBO can be time-intensive. This operation can be replaced simply by creating a basic mission in the "Missions" or "MPmissions" (if your feature is multiplayer-specific) folder of your game installation, and running the mission locally. The easiest way of accomplishing this is by the use of Event Scripts to run your code such as init.sqf. Once you have tested your code this way, you can then sequentially pack your PBO when major changes have been made, rather than for each debug session of a script or piece of code.
Debugging specific sections of code
Although primitive, the use of diag_log, systemChat/hint and format can be used to debug the content of variables when entering them into functions. In the case that specific pieces of code do not run, or if specific if conditions don't appear to fire, debugging the variable content with diag_log can be useful. As with all debugging, as long as the developer is methodical and logical in checking each section of code that runs, finding bugs and resolving them can be straightforward.
Debug Console
A Debug Console is a powerful tool; it is very helpful at debugging your scripting in real time.
- Arma 3
- The game already features Arma 3 Debug Console.
- Charon Productions' TroopMon3 for Arma 3 (alpha)
- Take On Helicopters
- The game already features TKOH Debug Console.
- Arma 2
- Str's Debug console
- Charon Productions' TroopMon3 for Arma 2 (TroopMon2 being obsolete and rewritten into this TroopMon3)
- DevCon by Kju
- Arma
- Charon Productions' TroopMon v0.8b - Complex debugging system providing lot of information for mission-makers, especially about AI.
- Str's Debug Console - available in all singleplayer missions, intros and outros. Easy and simple to use (Escape-Enter execute)
- Operation Flashpoint