Lou Montana/Sandbox – User

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Organising a bit)
Line 1: Line 1:
{{SideTOC}}
[[Debugging Techniques]] are ways in which developers can debug, or find out where errors or unexpected outcomes are occurring within their scripts.
[[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 '''I'''ntegrated '''D'''evelopment '''E'''nvironment or with other languages.




== Code ==
== Code ==


=== Syntax Highlight ===
Various links about code and how to write it:
* [[SQF syntax]]
* [[SQS syntax]]
* [[Code Optimisation]]


Syntax errors can be a frequent occurrence when developing scripts. '''Syntax highlight''' will help you find typos in commands
=== IDE and Syntax Highlight ===


[https://sites.google.com/site/macsarmatools/squint Squint] provides a fully-featured code editor which allows for syntax highlighting, displaying of errors and code correction.
Syntax errors can be a frequent occurrence when developing scripts. '''Syntax highlight''' will help you find typos in commands and in your scripts.<br />
A simpler solution of code highlighting for Notepad++ is also available, although errors will only be visible from the absence of highlighting.  
An '''I'''ntegrated '''D'''evelopment '''E'''nvironment, shortened to '''IDE''' is as its name says a development environment program, providing '''syntax highlight''' helping you writing code.<br />
The plugin will automatically check if you are using all commands with the proper syntax and with proper argument types.
<br />
Using [https://forums.bohemia.net/forums/topic/202181-sqdev-sqf-developing-in-eclipse/ SQDev] you will get code validation (linting) while you are typing it.
See further [[#Downloadable Tools|Downloadable Tools]] page section for download links.
 
Many tools are available:
* [https://forums.bohemia.net/profile/797692-sanjo/ Sanjo]'s Notepad++ SQF (npp-sqf): [http://www.armaholic.com/page.php?id=8680 Forum post] - [https://github.com/Sanjo/npp-sqf GitHub repository]
* [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]
* [[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]


=== Finding Errors ===
=== Finding Errors ===
Line 23: Line 21:
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.
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 [[Arma 3 Startup Parameters#Developer Options|<tt>-showScriptErrors</tt> startup parameter]] to display the error on-screen
* Be sure to use [[Arma 3 Startup Parameters#Developer Options|<tt>-showScriptErrors</tt> startup parameter]] to display the error on-screen
* Read [[Crash Files|RPT files]] for more information (make sure <tt>-noLogs</tt> startup parameter is not enabled or the logs will never be filled)
* 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)
** 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 '''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.
** Scripts running on a client use the '''ArmaX.RPT''' file.
** RPT files location is usualle <tt>%localappdata%\ArmaX</tt>
** RPT files location is usually <tt>%localappdata%\ArmaX</tt>


=== Removing Errors ===
=== Removing 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!!'''


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


==== Common errors ====
==== Common errors ====
* If a ''generic error'' happens on a [[sleep]]/[[uiSleep]]/[[waitUntil]], you may be in [[Scheduler#Unscheduled Environment|unscheduled environment]]
{| class="bikitable"
!Error message
!Cause
!Solution
|-
|<tt>Error Undefined variable in expression: _varName</tt>
|variable ''_varName'' has not been initialised properly in this context.
|
* in the case of a [[spawn]]ed code, previous local variables are '''not''' accessible and must be passed as arguments in order to access them.
* a variable may have been ''undefined'' ({{Inline code|_varName {{=}} [[nil]]}}). Unset it ''after'' you are done using it.
|-
|<tt>Error Zero divisor</tt>
|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.
|-
|<tt>Generic error</tt>
|Further code reading is required.
|* If it happens on a [[sleep]]/[[uiSleep]]/[[waitUntil]], you may be in [[Scheduler#Unscheduled Environment|unscheduled environment]].
|}


=== Working with Addons ===
=== Working with Addons ===
Line 47: Line 64:


=== Debugging specific sections 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.
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.
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.
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 ==
== Downloadable 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.
A '''Debug Console''' is a powerful tool; it is very helpful at debugging your scripting in real time.
Line 70: Line 98:
** [[User:Vektorboson|Vektorboson]]'s [http://home.arcor.de/vektorboson/res/console_3.7z Debug Console]
** [[User:Vektorboson|Vektorboson]]'s [http://home.arcor.de/vektorboson/res/console_3.7z Debug Console]


=== Emulators and Debuggers ===


== Tools ==
* [[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]
* {{arma3}}
* [[User:Dedmen|Dedmen]]'s [https://github.com/dedmen/ArmaDebugEngine Arma Debug Engine]
** [[User:X39|X39]]'s [https://forums.bohemia.net/forums/topic/210118-sqf-vm-an-sqf-emulator/ SQF VM] - an SQF emulator
<!--
* {{arma2}}
** -
* {{arma}}
** -
* {{ofp}}
** -
-->




[[Category:Operation Flashpoint: Editing]]
[[Category:ArmA: Editing]]
[[Category:ArmA 2: Editing]]
[[Category:Take_On Helicopters: Editing]]
[[Category:Arma 3: Editing]]
[[Category:Arma 3: Editing]]
[[Category:ArmA 2: Editing]]
[[Category:ArmA: Editing]]
[[Category:Operation Flashpoint: Editing]]
[[Category:Scripting Topics]]
[[Category:Scripting Topics]]




[[Category:Sandbox]]
[[Category:Sandbox]]

Revision as of 23:32, 19 February 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.


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

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.

Removing Errors

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

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 avoid 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