It is currently Fri Feb 28, 2020 1:14 pm

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 ->
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 functions to do this for me
-- use this to out co-ordinates
function debug_cords(place)"------------------------  Vec3.y = " .. place.y .. "  Vec.x = " .. place.x .. " Vec.z = " .. place.z )

-- if you do not know what type of data object you are dealing with use this function to dump it out to dcs.log
function debug_object(object, name)
   local result_table = routines.utils.oneLineSerialize(object)
   if name == nil then
      name = ""
   end"  " )"-------------- DEBUG OBJECT START " .. name .. " ----- DEBUG OBJECT START " " ----- DEBUG OBJECT START " " --------------") result_table )"-------------- DEBUG OBJECT END " .. name .. " ----- DEBUG OBJECT END " " ----- DEBUG OBJECT END " " --------------")"  ")
end -- EOF

-- if you know it is an array table use this function (name is used to make output pretty and ID it)
function debug_array( t_table, name )
   if name == nil then
      name = ""
   end"  " )"-+-+-+-+-+-+-+ DEBUG ARRAY START " .. name .. " +-+-+ DEBUG ARRAY START " " +-+-+ DEBUG ARRAY START " " +-+-+-+-+-+-+-")
   for i, item in ipairs(t_table) do" -+-+ Index " .. tostring(i) .. " - " .. tostring(item))
   end"-+-+-+-+-+-+-+ DEBUG ARRAY END " .. name .. " +-+-+ DEBUG ARRAY END " " +-+-+ DEBUG ARRAY 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