It is currently Sun Dec 16, 2018 1:22 am

All times are UTC

Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Sat Sep 29, 2018 11:37 am 

Joined: Tue Dec 19, 2017 1:41 pm
Posts: 6
I hope this little guide can help you out when debugging MOOSE scripts in DCS World

URL for static MOOSE develop branch ->

1. Get some tools to help you out.
Text editor -> Notepad++ -
Log viewer -> hoo wintail -
Log viewer -> glogg -

2. Get to know your dcs.log
Which is found in C:\Users\USERNAME\Saved Games\DCS or C:\Users\USERNAME\Saved Games\DCS.openbeta\Logs
is one file you will be wanting to monitor to keep an eye on what your scripts are doing, use one of the above
tools to do this. When something is not working right checking the log can help you debug it

3. Learn how to load scripts dynamically ->
This will make you debugging faster and easier to do eg you want to test a new function
this will save you a lot of time - Big shout to out to Pikster for creating this video - I owe you a lot of hours of my life i got back

4. RTFM - Read the fine Manual
If in doubt about something go have a look at the MOOSE docs
New MOOSE docs ->
MOOSE docs -> Older but easy to Navigate ->
Then go have a look at some of the demo missions
here ->
Play the mission, open the mission , examine and have a look at the script inside and learn
Hoggit has a Wiki of DCS scripting functions ->

5. Watch some Youtube tutorial videos
Flightcontrol has made a lot of good tutorial videos talking you through some of the features
that MOOSE has, these are great for the more "visual" type learners out there
His video channel ->

6. Use debug output statements to help see where you code flow is going:

number_of_bugs_in_DCS = 5
function test_function() -- this is defining the function itself

local value = false

if number_of_bugs_in_DCS < 1 then
value = true" ++++++++ Debug Output - Bugs = Zero - This is either a miracle or you are high")
elseif number_of_bugs_in_DCS < 10 then
value = false" ++++++++ Debug Output - Bugs < 10 - some text")

return value
end -- EOF

test_function() -- this is the call to the above function

This simple example above shows how to use simple debug output to the dcs.log file to show which parts
of the code are actually being executed when it is run.

7. Use debug output to work out what data is inside an object
(what it is made up of) Sometimes you might not be sure of what data items are contained in an object,
so it would be nice to be able to peek inside. I use this simple function to do this for me

function debug_object(object, name) -- name is an identifer string just to help spot what u are looking for in log
local result_table = routines.utils.oneLineSerialize(object)
if name == nil then
name = ""
end"-------------- DEBUG START " .. name .. " ----- DEBUG START " " ----- DEBUG START " " --------------") result_table )"-------------- DEBUG END " .. name .. " ----- DEBUG END " " ----- DEBUG END " " --------------")
end -- EOF

example call:
debug_object( test_zone, " TEST ZONE " ) -- send a zone object into the function and print out out " TEST ZONE " is just so delimiter text
There is more info on the built in debug output from MOOSE itself here ->
Delta99 Will be writing full guide to help users use this shortly (he is an expert in this)

8. Example script mistake
- mission started but things did not work right - a Menu was missing
A) pause the mission - lets not create anymore log data to trawl through than we need to
B) lets see what the dcs.log has to say - start from top and work downwards until you see errors

log shows this

2018-09-29 11:16:10.279 INFO SCRIPTING: 11654( 12320)/E: SET_GROUP02692._FilterStart({[1]=Adding Object:,[2]=Transport Helicopter,})
2018-09-29 11:16:10.280 ERROR DCS: Mission script error: : [string "C:\Users\Matej\AppData\Local\Temp\DCS.openbeta\/~mis0000182B"]:35287: attempt to index field 'CargoGroup' (a nil value)
stack traceback:
[C]: ?
[string "C:\Users\Matej\AppData\Local\Temp\DCS.openbeta\/~mis0000182B"]:35287: in function 'New'
[string "C:\Users\Matej\AppData\Local\Temp\DCS.openbeta\/~mis00004AA2"]:37: in main chunk
2018-09-29 11:16:10.281 INFO SCRIPTING: 11654( 12320)/E: SET_GROUP02704._FilterStart({[1]=Adding Object:,[2]=AWACS,})
2018-09-29 11:16:10.281 INFO SCRIPTING: 11654( 12320)/E: SET_GROUP02704._FilterStart({[1]=Adding Object:,[2]=EWR,})

To work out WTF has gone wrong we work BACKWARDS from the bottom up of the error
[string "C:\Users\Matej\AppData\Local\Temp\DCS.openbeta\/~mis00004AA2"]:37: in main chunk
^ this is telling us that on line 37 of our script something has went wrong

So we go to line 37 which is
local AttackCargoAlpha = CARGO_GROUP:New( GROUP:FindByName( "Attack" ), "Attack", "Assault Team Alpha", 500 ):RespawnOnDestroyed( false )

and try and work out which of the things we are sending to the CARGO_GROUP:New function thing are wrong. So we examine the code
above this paying attention to the spelling / case of the items defined. If that seems ok then time to look at the ME
Did I name the things Iam trying to reference in the script correectly ? no typos or EXTRA spaces ? (not it can be hard to spot an extra
space in the DCS ME - so take care)

Develop Environment
if you are more adventurous you can grab the source and set-up a dev env
Dev Environment -> Eclipse -
Github for downloading Repo ->
Github URL for Develop branch ->
Webpage for develop branch ->
In eclipse you can use Control + H, to do a search for info on functions etc

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group