size={900,90} 

local MS = loadFont('Tuffy_Bold.otf')
local clColor = {0.8,0.7,0.6, 0.50}

xpdr = globalProperty("sim/cockpit/radios/transponder_code")

xpdr1 = createGlobalPropertyf("ksgy/L410/avionics/xpdr1")
xpdr2 = createGlobalPropertyf("ksgy/L410/avionics/xpdr2")
xpdr3 = createGlobalPropertyf("ksgy/L410/avionics/xpdr3")
xpdr4 = createGlobalPropertyf("ksgy/L410/avionics/xpdr4")

function initTransponder()
	local xp_code = get(xpdr)
	local digit1 = math.floor(xp_code / 1000)
	local digit2 = math.floor((xp_code - digit1 * 1000 ) * 100)
	local digit3 = math.floor((xp_code - digit1 * 1000 - digit2 / 100 ) * 10)
	local digit4 = (xp_code - digit1 * 1000 - digit2 * 100 - digit3 / 10)
	set(xpdr1, digit1 * 1000)
	set(xpdr2, digit2 * 100)
	set(xpdr3, digit3 * 10)
	set(xpdr4, digit4)
end

initTransponder()

function update()
	if get(xpdr) ~= get(xpdr1) + get(xpdr2) + get(xpdr3) + get(xpdr4) then
		set(xpdr, get(xpdr1) + get(xpdr2) + get(xpdr3) + get(xpdr4))
	end
end

function draw()
	drawAll(components)
	drawText(MS, 0, 0, string.sub(string.format("%04d", get(xpdr)), 1, 1), 18, true, false, TEXT_ALIGN_CENTER, clColor)
	drawText(MS, 22, 0, string.sub(string.format("%04d", get(xpdr)), 2, 2), 18, true, false, TEXT_ALIGN_CENTER, clColor)
	drawText(MS, 42, 0, string.sub(string.format("%04d", get(xpdr)), 3, 3), 18, true, false, TEXT_ALIGN_CENTER, clColor)
	drawText(MS, 64, 0, string.sub(string.format("%04d", get(xpdr)), 4, 4), 18, true, false, TEXT_ALIGN_CENTER, clColor)
end