Adding a condition statement

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Post Reply
Message
Author
User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Adding a condition statement

#41 Post by Sling »

Very strange it works perfectly here. Can you post a screen shot showing the full code pane. You must have something else different.

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Adding a condition statement

#42 Post by Sling »

Ignore that last request i now see the error after inputting a frequency. I'll post back the solution.

vangyver
Posts: 127
Joined: Sat Dec 05, 2015 8:30 am

Re: Adding a condition statement

#43 Post by vangyver »

-- Add images in Z-order --
img_add_fullscreen("KX165A.png")
redline = img_add("redline.png", 364, 10, 2, 300)

-- Add text --
txt_com1 = txt_add(" ", "size:55px; color:#DCF509; halign:left", 25, 90, 200, 200)
txt_com1stby = txt_add(" ", "size:55px; color:#DCF509; halign:left", 200, 90, 200, 200)

txt_nav1 = txt_add(" ", "size:55px; color:#DCF509; halign:left", 365, 90, 200, 200)
txt_nav1stby = txt_add(" ", "size:55px; color:#DCF509; halign:left", 520, 90, 200, 200)

-- Set default visibility --
img_visible(redline, false)

--subscribe callback --
function new_navcomm_FSX(avionics, nav1, nav1stby, com1, com1stby, battery, generator, FuseNavCom1)

print("A"..avionics.." "..battery, generator, FuseNavCom1)

--make a boolean power variable based on state of avionics, battery, generator and FuseNavCom1
local power = avionics >= 8 and (battery >= 8 or generator) and FuseNavCom1 == 1
img_visible(redline, power)

if power then
txt_set(txt_com1, string.format("%d.%.02d",com1/100, com1%100) )
txt_set(txt_com1stby, string.format("%d.%.02d",com1stby/100, com1stby%100))
txt_set(txt_nav1, string.format("%d.%.02d",nav1/100, nav1%100))
txt_set(txt_nav1stby, string.format("%d.%.02d",nav1stby/100, nav1stby%100) )
else
txt_set(txt_com1, " ")
txt_set(txt_com1stby, " ")
txt_set(txt_nav1, " ")
txt_set(txt_nav1stby, " ")
end

end

--subscribes --
fsx_variable_subscribe("ELECTRICAL AVIONICS BUS VOLTAGE", "Volts",
"NAV ACTIVE FREQUENCY:1", "Mhz",
"NAV STANDBY FREQUENCY:1", "Mhz",
"COM ACTIVE FREQUENCY:1", "Mhz",
"COM STANDBY FREQUENCY:1", "Mhz",
"ELECTRICAL BATTERY BUS VOLTAGE", "Volts",
"GENERAL ENG GENERATOR SWITCH:1", "Bool",
"L:FuseNavCom1", "enum", new_navcomm_FSX)

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Adding a condition statement

#44 Post by Sling »

Try this on lines 25 to 28. That should be it this time.

Code: Select all

txt_set(txt_com1, string.format("%07.03f",com1/100, com1%100) )
txt_set(txt_com1stby, string.format("%07.03f",com1stby/100, com1stby%100))
txt_set(txt_nav1, string.format("%06.02f",nav1/100, nav1%100))
txt_set(txt_nav1stby, string.format("%06.02f",nav1stby/100, nav1stby%100) )
You may have to alter the text positioning slightly by altering the txt_add() function x and y values if the image is now a little off because there was a slight shift when the text functions changed.
Last edited by Sling on Mon Aug 16, 2021 6:24 am, edited 1 time in total.

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Adding a condition statement

#45 Post by Keith Baxter »

Hi,

Yes Tony is correct. I was about to post the same.

This is the string formatting one should use.

http://siminnovations.com/wiki/index.ph ... formatting

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Adding a condition statement

#46 Post by Sling »

Famous last words. I also just realised that the font sizes went all different when that change came about so the font size needs reducing. I also notice that you don't have 8.33khz com frequency spacing enabled so the string formatting for the com's needs to be the same as the nav's. To make things easy I've posted the whole corrected code below. Adjust the text size to suit.

Code: Select all

-- Add images in Z-order --
img_add_fullscreen("KX165A.png")
redline = img_add("redline.png", 364, 10, 2, 300)

-- Add text --
txt_com1 = txt_add(" ", "size:25px; color:#DCF509; halign:left", 25, 40, 200, 200)
txt_com1stby = txt_add(" ", "size:25px; color:#DCF509; halign:left", 200, 40, 200, 200)

txt_nav1 = txt_add(" ", "size:25px; color:#DCF509; halign:left", 365, 40, 200, 200)
txt_nav1stby = txt_add(" ", "size:25px; color:#DCF509; halign:left", 520, 40, 200, 200)

-- Set default visibility --
img_visible(redline, false)

--subscribe callback --
function new_navcomm_FSX(avionics, nav1, nav1stby, com1, com1stby, battery, generator, FuseNavCom1)

    --make a boolean power variable based on state of avionics, battery, generator and FuseNavCom1
    local power = avionics >= 8 and (battery >= 8 or generator) and FuseNavCom1 == 1
    img_visible(redline, power)

    if power then
        txt_set(txt_com1, string.format("%06.02f",com1, com1%1) )
        txt_set(txt_com1stby, string.format("%06.02f",com1stby, com1stby%1))
        txt_set(txt_nav1, string.format("%06.02f",nav1, nav1%1))
        txt_set(txt_nav1stby, string.format("%06.02f",nav1stby, nav1stby%1) )
    else
        txt_set(txt_com1, " ")
        txt_set(txt_com1stby, " ")
        txt_set(txt_nav1, " ")
        txt_set(txt_nav1stby, " ")
    end

end

--subscribes --
fsx_variable_subscribe("ELECTRICAL AVIONICS BUS VOLTAGE", "Volts",
"NAV ACTIVE FREQUENCY:1", "Mhz",
"NAV STANDBY FREQUENCY:1", "Mhz",
"COM ACTIVE FREQUENCY:1", "Mhz",
"COM STANDBY FREQUENCY:1", "Mhz",
"ELECTRICAL BATTERY BUS VOLTAGE", "Volts",
"GENERAL ENG GENERATOR SWITCH:1", "Bool",
"L:FuseNavCom1", "enum", new_navcomm_FSX)
Last edited by Sling on Mon Aug 16, 2021 6:50 am, edited 3 times in total.

vangyver
Posts: 127
Joined: Sat Dec 05, 2015 8:30 am

Re: Adding a condition statement

#47 Post by vangyver »

Untitled-3.jpg

vangyver
Posts: 127
Joined: Sat Dec 05, 2015 8:30 am

Re: Adding a condition statement

#48 Post by vangyver »

does not match freq.
Should I copy your last full script. I had to decrease font size to 25px

vangyver
Posts: 127
Joined: Sat Dec 05, 2015 8:30 am

Re: Adding a condition statement

#49 Post by vangyver »

Ok , copied last full script. Freq does not match. Adjust font size and position
Untitled-3.jpg

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Adding a condition statement

#50 Post by Sling »

Sorry this is taking a few iterations but we are working with P3D which i don't have and an aircraft i also don't have. It looks like A2A are using frequencies that don't require the divide by 100 so just remove the /100 like this.

Code: Select all

txt_set(txt_com1, string.format("%06.02f",com1, com1%1) )
txt_set(txt_com1stby, string.format("%06.02f",com1stby, com1stby%1))
txt_set(txt_nav1, string.format("%06.02f",nav1, nav1%1))
txt_set(txt_nav1stby, string.format("%06.02f",nav1stby, nav1stby%1) )

Post Reply