Lou Montana/Sandbox – User

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Debugging Techniques stub update (merging with X39's edits)
m (Debugging Techniques stub update)
Line 16: Line 16:
<br />
<br />
See further [[#Downloadable Tools|Downloadable Tools]] page section for download links.
See further [[#Downloadable Tools|Downloadable Tools]] page section for download links.
=== Errors ===
An error in SQF will purely and simply halt the current script, leading to unpredictable behaviour.
An error is not something that should happen, as it can hinder performance as well as break a mission.


=== Finding Errors ===
=== Finding Errors ===
Line 23: Line 28:
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).
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).


{{Important|For Arma 3, you need to enable ''Show Script Errors'' in the Launcher or set the corresponding [[Arma_3_Startup_Parameters|-showScriptErrors]] flag}}
{{Important|You need to enable ''Show Script Errors'' in the Launcher (for {{arma3}}) or set the corresponding [[Arma_3_Startup_Parameters|-showScriptErrors]] executable flag.}}


A script error will greet you with this box:
A script error will greet you with this box:
Line 37: Line 42:
* To ensure error location in your script, prefer [[preprocessFileLineNumbers]] to [[preprocessFile]]
* To ensure error location in your script, prefer [[preprocessFileLineNumbers]] to [[preprocessFile]]
* Read [[Crash Files|RPT files]] for more information (make sure [[Arma 3 Startup Parameters#Performance|<tt>-noLogs</tt> startup parameter]] is '''not''' enabled or the logs will never be filled)
* Read [[Crash Files|RPT files]] for more information (make sure [[Arma 3 Startup Parameters#Performance|<tt>-noLogs</tt> 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 server use the '''Arma''X''Server.RPT''' file which has varying location depending upon the type of server being run.
** Scripts running on a client use the '''ArmaX.RPT''' file.
** Scripts running on a client use the '''Arma''X''.RPT''' file.
** RPT files location is usually <tt>%localappdata%\ArmaX</tt>




==== RPT files ====
==== RPT files ====
An [[arma.RPT|RPT]] (or [[Crash Files|crash file]) is the game's log file; it will dump debug information as well as encountered errors.
An [[arma.RPT|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]].
One can also dump information in it by using commands like [[diag_log]].


{{Feature arma3|The RPT file might be disabled using the Arma 3 launcher or by setting the corresponding [[Arma_3_Startup_Parameters|-noLogs]] flag.}}
{{Important|The RPT file might be disabled using the Arma 3 launcher or by setting the corresponding [[Arma_3_Startup_Parameters|-noLogs]] flag ({{arma3}} or {{arma2oa}} option)}}


{|class="bikitable"
{|class="bikitable"
|+ RPT File location per game
|+ RPT File location per game (See [[Crash Files]] for more information)
!Game
!Game
!Location
!Location
!Files
|-
|-
| {{GVI|arma3|1.00}} {{arma3}}
| {{GVI|arma3|1.00}} {{arma3}}
| <code>'''%userprofile%'''\AppData\Local\Arma 3</code>
| <code>'''%localappdata%'''\Arma 3</code>
| <code>Arma3_x64_yyyy-mm-dd_hh-mm-ss.rpt</code>
|-
|-
| {{GVI|arma2|1.00}} {{arma2}}
| {{GVI|arma2|1.00}} {{arma2}}
| <code>'''%userprofile%'''\AppData\Local\ArmA 2</code>
| <code>'''%localappdata%'''\ArmA 2</code>
| <code>arma2.rpt</code>
|-
|-
| {{GVI|arma|1.00}} {{arma}}
| {{GVI|arma|1.00}} {{arma}}
| <code>'''%userprofile%'''\AppData\Local\ArmA</code>
| <code>'''%localappdata%'''\ArmA</code>
| <code>arma.rpt</code>
|-
|-
| {{GVI|ofp|1.00}} {{ofp}}
| {{GVI|ofp|1.00}} {{ofp}}
| <code>'''''OFP root directory'''''\flashpoint.rpt</code>
| <code>'''''OFP root directory'''''</code>
<code>'''''OFP root directory'''''\context.bin</code>
| <code>flashpoint.rpt<br />context.bin</code>
|}
|}




=== Removing Errors ===
=== Solving Errors ===


Once the script error is located: '''be sure to check the BiKi page corresponding to the command/function you are using!!'''
Once the script error is located: '''be sure to check the BiKi page corresponding to the command/function you are using!!'''
Line 78: Line 86:
The same can be done for non-critical errors like when a method is "just" computing the wrong values.
The same can be done for non-critical errors like when a method is "just" computing the wrong values.


{{Informative|If you're having great difficulty solving a problem, the good way is to bring the issue to the simplest code;
{{Informative|
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.
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!}}
Doing so will save you dealing with other scripts' potential side effects!}}
Line 84: Line 93:


==== Common errors ====
==== Common errors ====
{| class="bikitable"
{| class="bikitable sortable"
!Error message
!Error message
!Cause
!Cause
Line 97: Line 106:
|<tt>Error Zero divisor</tt>
|<tt>Error Zero divisor</tt>
|Pretty self-explanatory, somewhere in your code is a division by zero.
|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.
|
* Make sure to check if your divisor is different from zero before dividing.
|-
|-
|<tt>Generic error</tt>
|<tt>Generic error</tt>
|Further code reading is required.
|Further code reading is required.
|* If it happens on a [[sleep]]/[[uiSleep]]/[[waitUntil]], you may be in [[Scheduler#Unscheduled Environment|unscheduled environment]].
|
* If it happens on a [[sleep]]/[[uiSleep]]/[[waitUntil]], you may be in [[Scheduler#Unscheduled Environment|unscheduled environment]].
|}
|}


Line 111: Line 122:


=== Debugging specific sections 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.
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.
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.
Line 116: Line 128:




== Downloadable Tools ==
== Debugging Tools ==
 
=== IDE ===
* [[User:Sbsmac|Sbsmac]]'s '''Squint''': [https://forums.bohemia.net/forums/topic/101921-squint-the-sqf-editor-and-error-checker/ Forum post] - [https://sites.google.com/site/macsarmatools/squint website]<br />Provides a fully-featured code editor which allows for syntax highlighting, displaying of errors and code correction.
* [https://forums.bohemia.net/profile/1044335-krzmbrzl/ krzmbrzl]'s '''SQDev''': [https://forums.bohemia.net/forums/topic/202181-sqdev-sqf-developing-in-eclipse/ Forum post] - [https://github.com/Krzmbrzl/SQDev GitHub repository]<br />Provides code validation (linting) while you are typing it.
 
=== Syntax Highlight ===
* [https://forums.bohemia.net/profile/797692-sanjo/ Sanjo]'s '''Notepad++ SQF''' (npp-sqf, plugin for [https://notepad-plus-plus.org/download/ Notepad++]): [http://www.armaholic.com/page.php?id=8680 Forum post] - [https://github.com/Sanjo/npp-sqf GitHub repository]
 
=== Debug Console ===
A '''Debug Console''' is a powerful tool; it is very helpful at debugging your scripting in real time.
* {{arma3}}
** The game already features [[Mission Editor: Debug Console (Arma 3)|Arma 3 Debug Console]].
** [https://forums.bohemia.net/profile/761667-charon-productions/ Charon Productions]' [http://www.armaholic.com/page.php?id=19898 TroopMon3] for Arma 3 (alpha)
* {{tkoh}}
** The game already features [[Mission Editor: Debug Console (Take On Helicopters)|TKOH Debug Console]].
* {{arma2}}
** [[User:Str|Str]]'s [http://temp.moricky.com/arma2/stra_debug2.rar Debug console]
** [https://forums.bohemia.net/profile/761667-charon-productions/ Charon Productions]' [http://www.armaholic.com/page.php?id=7948 TroopMon3] for Arma 2 ([http://www.armaholic.com/page.php?id=7948 TroopMon2] being obsolete and rewritten into this TroopMon3)
** [http://forums.bistudio.com/showthread.php?t=126249 DevCon] by [[User:Kju|Kju]]
* {{arma}}
** [https://forums.bohemia.net/profile/761667-charon-productions/ Charon Productions]' [http://www.armaholic.com/page.php?id=727 TroopMon v0.8b] - Complex debugging system providing lot of information for mission-makers, especially about AI.
** [[User:Str|Str]]'s [http://www.armaholic.com/page.php?id=549 Debug Console] - available in all singleplayer missions, intros and outros. Easy and simple to use (Escape-Enter execute)
* {{ofp}}
** [[User:Vektorboson|Vektorboson]]'s [http://home.arcor.de/vektorboson/res/console_3.7z Debug Console]
 
=== Emulators and Debuggers ===
* [[User:X39|X39]]'s [https://forums.bohemia.net/forums/topic/210118-sqf-vm-an-sqf-emulator/ SQF VM] - an SQF emulator
* [[User:Dedmen|Dedmen]]'s [https://github.com/dedmen/ArmaScriptProfiler/ Arma Script Profiler]
* [[User:Dedmen|Dedmen]]'s [https://github.com/dedmen/ArmaDebugEngine Arma Debug Engine]


=== Others (table) ===
{| class="bikitable sortable"
{| class="bikitable"
! Game
! Game
! User
! User
! Addon/Toolname
! Addon/Toolname
! Category
! Description
! Description
! Link
! Link
|-
|-
<!--
|{{GVI|arma|1.00}}
|{{GVI|arma|1.00}}
|[[User:Vektorboson|Vektorboson]]
|[[User:Vektorboson|Vektorboson]]
|
|
|Debugging console
|Debug console
|<s>[http://home.arcor.de/vektorboson/res/console_3.7z '''''LINK DEAD''''']</s>
|
|<s>[http://home.arcor.de/vektorboson/res/console_3.7z '''''DEAD LINK''''']</s>
-->
|-
|-
|{{GVI|arma|1.00}}
|{{GVI|arma|1.00}}
|[[User:Str|Str]]
|[[User:Str|Str]]
|
|
|Debugging console (addon, available in intros, missions and outros)
|Debug console
|<s>[http://www.flashpoint1985.com/cgi-bin/ikonboard311/ikonboard.cgi?s=1593a8bb7375674288e681ba36b48dc3;act=ST;f=70;t=56294 '''''LINK DEAD''''']</s>
|available in all singleplayer missions, intros and outros. Easy and simple to use (Escape-Enter execute)
|[http://www.armaholic.com/page.php?id=549 download]
|-
|-
|{{GVI|arma|1.0}}
|{{GVI|arma|1.00}}
|Charon Productions
|[https://forums.bohemia.net/profile/761667-charon-productions/ Charon Productions]
|TroopMon
|TroopMon v0.8b
|Debugging system containing informations relevant to mission-makers (especially about AI)
|Debug system
|<s>[http://www.flashpoint1985.com/cgi-bin/ikonboard311/ikonboard.cgi?s=c10d84cce14a63a54ac915506d008e80;act=ST;f=69;t=57493 '''''LINK DEAD''''']</s>
|Complex debugging system providing lots of information for mission-makers, especially about AI.
|[[http://www.armaholic.com/page.php?id=727 download]
|-
|-
|{{GVI|arma2|1.00}}
|{{GVI|arma2|1.00}}
Line 177: Line 165:
|
|
|Debug console
|Debug console
|
|[http://temp.moricky.com/arma2/stra_debug2.rar download]
|[http://temp.moricky.com/arma2/stra_debug2.rar download]
|-
|-
|{{GVI|arma2|1.00}}
|{{GVI|arma2|1.00}}
|Charon Productions
|[https://forums.bohemia.net/profile/761667-charon-productions/ Charon Productions]
|TroopMon3
|TroopMon v3<br />TroopMon v2 (obsolete)
|Debug system
|Debugging system containing informations relevant to mission-makers (especially about AI)
|Debugging system containing informations relevant to mission-makers (especially about AI)
|[http://www.armaholic.com/page.php?id=7948 download]
|[http://www.armaholic.com/page.php?id=19898 download]<br />[http://www.armaholic.com/page.php?id=7948 TroopMon v2]
|-
|-
|{{GVI|arma2|1.00}}
|{{GVI|arma2|1.00}}
|[[User:Kju|Kju]]
|[[User:Kju|Kju]]
|DevCon
|DevCon
|Debug console
|
|
|[http://forums.bistudio.com/showthread.php?t=126249 download]
|[http://forums.bistudio.com/showthread.php?t=126249 download]
|-
|-
<!--
|{{GVI|arma2|1.00}}
|{{GVI|arma2|1.00}}
|Chain of Command
|Chain of Command
|Binary gamefile viewer
|Binary gamefile viewer
|Tool
|Allows to check variables and script states in save files
|Allows to check variables and script states in save files
|<s>[http://ofp.gamepark.cz/index.php?showthis=6989&newlang=eng '''''LINK DEAD''''']</s>
|<s>[http://ofp.gamepark.cz/index.php?showthis=6989&newlang=eng '''''DEAD LINK''''']</s>
-->
|-
|-
|{{GVI|tkoh|1.00}}
|{{GVI|tkoh|1.00}}
|[[Bohemia_Interactive|Bohemia Interactive]]
|[[Bohemia_Interactive|Bohemia Interactive]]
| ''N/A''
| ''N/A''
|Debug console
|Debug Console capable of executing code and more.
|Debug Console capable of executing code and more.
|[[Mission_Editor:_Debug_Console_(Take_On_Helicopters)|Shipped With Game]]
|[[Mission Editor: Debug Console (Take On Helicopters)|Wiki page]]
|-
|-
|{{GVI|arma3|1.00}}
|{{GVI|arma3|1.00}}
|[[Bohemia_Interactive|Bohemia Interactive]]
|[[Bohemia_Interactive|Bohemia Interactive]]
| ''N/A''
| ''N/A''
|Debug console
|Debug Console capable of executing code and more.
|Debug Console capable of executing code and more.
|[[Mission_Editor:_Debug_Console_(Arma 3)|Shipped With Game]]
|[[Mission Editor: Debug Console (Arma 3)|Wiki page]]
|-
|*
|[[User:X39|X39]]
|SQF VM
|Emulator
|
|[https://forums.bohemia.net/forums/topic/210118-sqf-vm-an-sqf-emulator/ download]
|-
|*
|[[User:Dedmen|Dedmen]]
|Arma Script Profiler
|Tool
|
|[https://github.com/dedmen/ArmaScriptProfiler/ download]
|-
|*
|[[User:Dedmen|Dedmen]]
|Arma Debug Engine
|Tool
|
|[https://github.com/dedmen/ArmaDebugEngine/ download]
|-
|*
|[[User:Sbsmac|Sbsmac]]
|Squint
|IDE
|Provides a fully-featured code editor which allows for syntax highlighting, displaying of errors and code correction. [https://forums.bohemia.net/forums/topic/101921-squint-the-sqf-editor-and-error-checker/ Forum post]
|[https://sites.google.com/site/macsarmatools/squint download]
|-
|*
|[https://forums.bohemia.net/profile/1044335-krzmbrzl/ krzmbrzl]
|SQDev
|IDE
|Provides code validation (linting) while you are typing it. [https://forums.bohemia.net/forums/topic/202181-sqdev-sqf-developing-in-eclipse/ Forum post]
|[https://github.com/Krzmbrzl/SQDev download]
|-
|*
|[https://forums.bohemia.net/profile/797692-sanjo/ Sanjo]
|Notepad++ SQF
|IDE
|[https://notepad-plus-plus.org/download/ Notepad++] SQF Syntax highlighter plugin. [http://www.armaholic.com/page.php?id=8680 Forum post]
|[https://github.com/Sanjo/npp-sqf download]
|}
|}



Revision as of 22:45, 15 April 2019

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.

Errors

An error in SQF will purely and simply halt the current script, leading to unpredictable behaviour. An error is not something that should happen, as it can hinder performance as well as break a mission.

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).

You need to enable Show Script Errors in the Launcher (for Arma 3) or set the corresponding -showScriptErrors executable 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 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.

The RPT file might be disabled using the Arma 3 launcher or by setting the corresponding -noLogs flag (Arma 3 or Arma 2: Operation Arrowhead option)
RPT File location per game (See Crash Files for more information)
Game Location Files
Arma 3 logo black.png1.00 Arma 3 %localappdata%\Arma 3 Arma3_x64_yyyy-mm-dd_hh-mm-ss.rpt
Logo A2.png1.00 Arma 2 %localappdata%\ArmA 2 arma2.rpt
-wrong parameter ("Arma") defined!-1.00 Arma %localappdata%\ArmA arma.rpt
Logo A0.png1.00 Operation Flashpoint OFP root directory flashpoint.rpt
context.bin


Solving 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.

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.


Debugging Tools

Game User Addon/Toolname Category Description Link
-wrong parameter ("Arma") defined!-1.00 Str Debug console available in all singleplayer missions, intros and outros. Easy and simple to use (Escape-Enter execute) download
-wrong parameter ("Arma") defined!-1.00 Charon Productions TroopMon v0.8b Debug system Complex debugging system providing lots of information for mission-makers, especially about AI. [download
Logo A2.png1.00 Str Debug console download
Logo A2.png1.00 Charon Productions TroopMon v3
TroopMon v2 (obsolete)
Debug system Debugging system containing informations relevant to mission-makers (especially about AI) download
TroopMon v2
Logo A2.png1.00 Kju DevCon Debug console download
tkoh logo small.png1.00 Bohemia Interactive N/A Debug console Debug Console capable of executing code and more. Wiki page
Arma 3 logo black.png1.00 Bohemia Interactive N/A Debug console Debug Console capable of executing code and more. Wiki page
* X39 SQF VM Emulator download
* Dedmen Arma Script Profiler Tool download
* Dedmen Arma Debug Engine Tool download
* Sbsmac Squint IDE Provides a fully-featured code editor which allows for syntax highlighting, displaying of errors and code correction. Forum post download
* krzmbrzl SQDev IDE Provides code validation (linting) while you are typing it. Forum post download
* Sanjo Notepad++ SQF IDE Notepad++ SQF Syntax highlighter plugin. Forum post download