I hope this little guide can help you out when debugging MOOSE scripts in DCS World
URL for static MOOSE develop branch ->
https://github.com/FlightControl-Master/MOOSE_INCLUDE/tree/develop/Moose_Include_Static1. Get some tools to help you out. Text editor -> Notepad++ -
https://notepad-plus-plus.org/Log viewer -> hoo wintail -
http://www.hootech.com/WinTail/Log viewer -> glogg -
https://glogg.bonnefon.org/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 ->
https://www.youtube.com/watch?v=BMKBXjjKiDIThis 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 ManualIf in doubt about something go have a look at the MOOSE docs
New MOOSE docs ->
https://flightcontrol-master.github.io/MOOSE_DOCS_DEVELOP/Documentation/MOOSE docs -> Older but easy to Navigate ->
http://www.havoc-company.com/dcs/moose_docs/Then go have a look at some of the demo missions
here ->
https://github.com/FlightControl-Master/MOOSE_MISSIONS/tree/developPlay the mission, open the mission , examine and have a look at the script inside and learn
Hoggit has a Wiki of DCS scripting functions ->
https://wiki.hoggitworld.com/view/Category:Functions#5. Watch some Youtube tutorial videosFlightcontrol 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 ->
https://www.youtube.com/channel/UCjrA9j5LQoWsG4SpS8i79Qg6. 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
env.info(" ++++++++ Debug Output - Bugs = Zero - This is either a miracle or you are high")
elseif number_of_bugs_in_DCS < 10 then
value = false
env.info(" ++++++++ Debug Output - Bugs < 10 - some text")
end
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
env.info("-------------- DEBUG START " .. name .. " ----- DEBUG START " ..name.. " ----- DEBUG START "..name.. " --------------")
env.info( result_table )
env.info("-------------- DEBUG END " .. name .. " ----- DEBUG END " ..name.. " ----- DEBUG END "..name.. " --------------")
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 ->
https://flightcontrol-master.github.io/MOOSE_DOCS/Documentation/Core.Base.htmlDelta99 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 Environmentif you are more adventurous you can grab the source and set-up a dev env
Dev Environment -> Eclipse -
https://www.eclipse.org/ldt/Github for downloading Repo ->
https://desktop.github.com/Github URL for Develop branch ->
https://github.com/FlightControl-Master/MOOSE_INCLUDE.gitWebpage for develop branch ->
https://github.com/FlightControl-Master/MOOSE_INCLUDE/tree/developIn eclipse you can use Control + H, to do a search for info on functions etc