Skip to content

Snippets

Bailey edited this page Sep 23, 2022 · 7 revisions

Snips of code for reference

Dump Function

function dump(o)
   if type(o) == 'table' then
      local s = '{ '
      for k,v in pairs(o) do
         if type(k) ~= 'number' then k = '"'..k..'"' end
         s = s .. '['..k..'] = ' .. dump(v) .. ','
      end
      return s .. '} '
   else
      return tostring(o)
   end
end

DCS-Interface Send Data

ExportScript.Tools.SendData(8051, dataVariable)

Colored Circles

-- ⚪ white
-- ⚫ black
-- 🟡 yellow
-- 🔴 red
-- 🟢 green
-- 🔵 blue

One Line Statements

if omni_Xxx > 9 then omni_Xxx = 0 end

Correct DCS Argument Roller Rounding Error

if fuelQty_Xxxx > 9 then fuelQty_Xxxx = 0 end
if fuelQty_xXxx > 9 then fuelQty_xXxx = 0 end
if fuelQty_xxXx > 9 then fuelQty_xxXx = 0 end
if fuelQty_xxxX > 9 then fuelQty_xxxX = 0 end

Add comma to number

function format_int(number) --https://stackoverflow.com/questions/10989788/format-integer-in-lua
	local i, j, minus, int, fraction = tostring(number):find('([-]?)(%d+)([.]?%d*)')
	-- reverse the int-string and append a comma to all blocks of 3 digits
	int = int:reverse():gsub("(%d%d%d)", "%1,")
	-- reverse the int-string back remove an optional comma and put the
	-- optional minus and fractional part back
	return minus .. int:reverse():gsub("^,", "") .. fraction
end

Degree Symbol °

Delta Symbol Δ

Cockpit Params

return list_cockpit_params()

Device MetaTable Log Dump

function ExportScript.DeviceMetaTableLogDump(mainPanelDevice)
	local ltmp1 = 0
	for ltmp2 = 1, 30, 1 do
		ltmp1 = GetDevice(ltmp2)
		ExportScript.Tools.WriteToLog(ltmp2 .. ': ' .. ExportScript.Tools.dump(ltmp1))
		ExportScript.Tools.WriteToLog(ltmp2 ..' (metatable): '..ExportScript.Tools.dump(getmetatable(ltmp1)))
	end
end

ListIndication Log Dump

function ExportScript.ListIndicationLogDump(mainPanelDevice)
	local ltmp1 = 0
	for ltmp2 = 0, 30, 1 do
		ltmp1 = list_indication(ltmp2)
		ExportScript.Tools.WriteToLog(ltmp2 ..': '..ExportScript.Tools.dump(ltmp1))
	end
end

Custom Saved Games Folder

"...\DCS World OpenBeta\bin\DCS.exe" -w DCS.Test

Results in the folder called DCS.Test

Enable full debugging with log.set_output("dcs", "", log.ALL, log.FULL) in Saved Games\DCS.xxx\Config\autoexec.cfg

Clone this wiki locally