Lou Montana/Sandbox – User

From Bohemia Interactive Community
< User:Lou Montana
Revision as of 14:39, 15 April 2019 by Lou Montana (talk | contribs) (Debugging Techniques stub update (merging with X39's edits)
Jump to navigation Jump to search

Template:SideTOC Debugging Techniques are ways in which developers can debug, or find out where errors or unexpected outcomes are occurring within their scripts. Template:note

Code

Various links about code and how to write it:

IDE and Syntax Highlight

Syntax errors can be a frequent occurrence when developing scripts. Syntax highlight will help you find typos in commands and in your scripts.
An Integrated Development Environment, shortened to IDE is as its name says a development environment program, providing syntax highlight helping you writing code.

See further Downloadable Tools page section for download links.

Finding Errors

Debugging is, most of the time, literally as complicated as writing the actual code itself. You usually get hinted by the game, where some error happened, and what it was.
There are instances where actual error reason might be something completely different than announced(eg. you get the error on a variable being nil somewhere, but the actual error is that you mistyped it where you set it initially).

For Arma 3, you need to enable Show Script Errors in the Launcher or set the corresponding -showScriptErrors flag

A script error will greet you with this box:

Script error message

It tells you what went wrong, shows a snippet of the code that failed and, unless you used a command combination like eg. `compile loadFile`, what file and line it occured on. Knowing this, you now can proceed to find the actual reason why you errored on that specific piece of code.

Template:informative

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.


RPT files

An RPT (or [[Crash Files|crash file]) is the game's log file; it will dump debug information as well as encountered errors. One can also dump information in it by using commands like diag_log.

Arma 3
The RPT file might be disabled using the Arma 3 launcher or by setting the corresponding -noLogs flag.
RPT File location per game
Game Location
Arma 3 logo black.png1.00 Arma 3 %userprofile%\AppData\Local\Arma 3
Logo A2.png1.00 Arma 2 %userprofile%\AppData\Local\ArmA 2
-wrong parameter ("Arma") defined!-1.00 Arma %userprofile%\AppData\Local\ArmA
Logo A0.png1.00 Operation Flashpoint OFP root directory\flashpoint.rpt

OFP root directory\context.bin


Removing Errors

Once the script error is located: be sure to check the BiKi page corresponding to the command/function you are using!!

The most simple thing you can do is to output expected values. This can be done using for example diag_log or systemChat. Output yourself a few variables that relate to your problem (for example: When the error occurs because you land in some if block, output the corresponding variables inside of the if). You continue doing this until you hit the actual problem: When variable A is not set, go to where variable A gets set and check around there, repeat and continue.

The same can be done for non-critical errors like when a method is "just" computing the wrong values.

If you're having great difficulty solving a problem, the good way is to bring the issue to the simplest code;

take the mission part that doesn't work, paste it into a new test mission and work from here.

Doing so will save you dealing with other scripts' potential side effects!


Common errors

Error message Cause Solution
Error Undefined variable in expression: _varName variable _varName has not been initialised properly in this context.
  • in the case of a spawned code, previous local variables are not accessible and must be passed as arguments in order to access them.
  • a variable may have been undefined (_varName = nil). Unset it after you are done using it.
Error Zero divisor Pretty self-explanatory, somewhere in your code is a division by zero. * Make sure to check if your divisor is different from zero before dividing.
Generic error Further code reading is required. * If it 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 combined use of diag_log, systemChat/hint and format can help to debug the content of function arguments. 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.


Downloadable Tools

IDE

Syntax Highlight

Debug Console

A Debug Console is a powerful tool; it is very helpful at debugging your scripting in real time.

Emulators and Debuggers

Others (table)

Game User Addon/Toolname Description Link
-wrong parameter ("Arma") defined!-1.00 Vektorboson Debugging console LINK DEAD
-wrong parameter ("Arma") defined!-1.00 Str Debugging console (addon, available in intros, missions and outros) LINK DEAD
-wrong parameter ("Arma") defined!-1.0 Charon Productions TroopMon Debugging system containing informations relevant to mission-makers (especially about AI) LINK DEAD
Logo A2.png1.00 Str Debug console download
Logo A2.png1.00 Charon Productions TroopMon3 Debugging system containing informations relevant to mission-makers (especially about AI) download
Logo A2.png1.00 Kju DevCon download
Logo A2.png1.00 Chain of Command Binary gamefile viewer Allows to check variables and script states in save files LINK DEAD
tkoh logo small.png1.00 Bohemia Interactive N/A Debug Console capable of executing code and more. Shipped With Game
Arma 3 logo black.png1.00 Bohemia Interactive N/A Debug Console capable of executing code and more. Shipped With Game