Keith's LUA Help thread.

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

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

Keith's LUA Help thread.

#1 Post by Keith Baxter »

Hi all,

Please please please...

This thread is a request for help with this elephant I have created. I am re coding the menu and requesting best code practice. I will be posting code one small bite at a time until the elephant is eaten.

Below is code that shows different instruments in a tile. Here are two options that I have come up with. Which one is the best. Or is there a better way.

As most of the menu requires similar code I want to get concept right before I start on the rest of the buttons and encoders.

Code: Select all

function dial_change05(direction)

	mini_tile_left = mini_tile_left + 1*direction 
	mini_tile_left = var_cap(mini_tile_left, 1,4)

funct_dc05a_group=group_add(ed_1_grp,temp_nd2,coms_group,fms_flightplan_prog_group)visible(funct_dc05a_group,false)

	if     mini_tile_left ==1 then group_obj_remove(funct_dc05a_group, ed_1_grp) visible( ed_1_grp,true)visible(funct_dc05a_group,false)
	elseif mini_tile_left ==2 then group_obj_remove(funct_dc05a_group, temp_nd2) visible( temp_nd2,true)visible(funct_dc05a_group,false)
	elseif mini_tile_left ==3 then group_obj_remove(funct_dc05a_group, coms_group) visible( coms_group,true)visible(funct_dc05a_group,false)   
	elseif mini_tile_left ==4 then group_obj_remove(funct_dc05a_group, fms_flightplan_prog_group) visible( fms_flightplan_prog_group,true)visible(funct_dc05a_group,false)
	end
end

Code: Select all

function dial_change05(direction)

	mini_tile_left = mini_tile_left + 1*direction 
	mini_tile_left = var_cap(mini_tile_left, 1,4)

	if mini_tile_left ==1 then visible( ed_1_grp,true) elseif mini_tile_left ~=1 then visible( ed_1_grp,false)end
	if mini_tile_left ==2 then visible( temp_nd2,true) elseif mini_tile_left ~=2 then visible( temp_nd2,false)end
	if mini_tile_left ==3 then visible( coms_group,true) elseif mini_tile_left ~=3 then visible( coms_group,false)end 
	if mini_tile_left ==4 then visible( fms_flightplan_prog_group,true)elseif mini_tile_left ~=4 then visible(fms_flightplan_prog_group,false)end 
	
end
This is what the code does.

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
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Keith's LUA Help thread.

#2 Post by Keith Baxter »

As Gilles has pointed out to me I should get my conventions sorted and add more comment so that it is easily understood.

Please comment if this is what is correct.

Code: Select all

function dial_change05(tile_1)
---This function changes the visibility of instruments in tile no1
	mini_tile_left = mini_tile_left + 1*tile_1 
	mini_tile_left = var_cap(mini_tile_left, 1,4)
	
---Show the edis 1 instrument
	if mini_tile_left ==1 then 
		visible( ed_1_grp,true)
	else
		visible( ed_1_grp,false)
	end
---Show the ND instrument	
	if mini_tile_left ==2 then 
		visible( temp_nd2,true)
	else 
		visible( temp_nd2,false)
	end
---Show the coms display	
	if mini_tile_left ==3 then 
		visible( coms_group,true)
	else 
		visible( coms_group,false)
	end 
---Show the Flight Plan Progress	
	if mini_tile_left ==4 then 
		visible( fms_flightplan_prog_group,true)
	else
		visible(fms_flightplan_prog_group,false)
	end 
	
end
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 

SimPassion
Posts: 5336
Joined: Thu Jul 27, 2017 12:22 am

Re: Keith's LUA Help thread.

#3 Post by SimPassion »

Nice Keith

it will help to go forward

Regards
Gilles

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

Re: Keith's LUA Help thread.

#4 Post by Keith Baxter »

SimPassion wrote: Mon Nov 05, 2018 5:40 am Nice Keith

it will help to go forward

Regards
Gilles
Thank you Gilles

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: Keith's LUA Help thread.

#5 Post by Sling »

Keith,

Sorry it's been a while. I've been busy. Both the code examples you posted are unnecessarily complex. You can simply do what you want with 5 lines of code. Don't forget to add plenty of comments as Gilles suggested.

Did you watch the visibility tutorial? I think I showed an example of this technique.

Tony

Code: Select all

function dial_change05(direction)

	mini_tile_left = var_cap(mini_tile_left + direction, 1,4)
	visible(ed_1_grp, mini_tile_left == 1)
	visible(temp_nd2, mini_tile_left == 2)
	visible(coms_group, mini_tile_left == 3)
	visible(fms_flightplan_prog_group, mini_tile_left == 4)	
end

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

Re: Keith's LUA Help thread.

#6 Post by Keith Baxter »

Sling wrote: Thu Nov 15, 2018 7:58 am Keith,

Sorry it's been a while. I've been busy. Both the code examples you posted are unnecessarily complex. You can simply do what you want with 5 lines of code. Don't forget to add plenty of comments as Gilles suggested.

Did you watch the visibility tutorial? I think I showed an example of this technique.

Tony

Code: Select all

function dial_change05(direction)

	mini_tile_left = var_cap(mini_tile_left + direction, 1,4)
	visible(ed_1_grp, mini_tile_left == 1)
	visible(temp_nd2, mini_tile_left == 2)
	visible(coms_group, mini_tile_left == 3)
	visible(fms_flightplan_prog_group, mini_tile_left == 4)	
end
Thank you Tony,

That looks really simple.

Because each hardware function can do multiple things I take it that that code can be put in an if statement like this.

Code: Select all

function dial_change05(direction)
if map_button ~=1 and map button ~= 3 then
	mini_tile_left = var_cap(mini_tile_left + direction, 1,4)
	visible(ed_1_grp, mini_tile_left == 1)
	visible(temp_nd2, mini_tile_left == 2)
	visible(coms_group, mini_tile_left == 3)
	visible(fms_flightplan_prog_group, mini_tile_left == 4)	
end
if chart_button ==2 then

code to zoom the chart etc

end

end
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
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Keith's LUA Help thread.

#7 Post by Keith Baxter »

Am I doing this correctly ? It works but I think there is an easier way.

This is the code to display when the menu is selected.

Code: Select all

--====================================================================================================================================================--
------------------------------------------------------ AIRPORT INFO MENU 2 -----------------------------------------------------------------------------
--====================================================================================================================================================--

near_arpt1_text_L=txt_add("Nearest Airports", "font:ARIALI.TTF; size:18px; color:white; halign:left;", 118, 450, 200, 30)visible(near_arpt1_text_L,false)
airp_run1_text=txt_add("Runways","font:ARIALI.TTF; size:18; color:white; halign:left;", 120, 450, 200, 20)visible(airp_run1_text,false) 
airp_run2_text=txt_add("RWY","font:arial.ttf; size:16; color:#5599FF; halign:left;", 120, 480, 200, 20)visible(airp_run2_text,false) 
airp_run3_text=txt_add("Direction","font:arial.ttf; size:16; color:#5599FF; halign:center;", 120, 480, 200, 20)visible(airp_run3_text,false) 
airp_run4_text=txt_add("Elevation","font:arial.ttf; size:16; color:#5599FF; halign:center;", 200, 480, 200, 20)visible(airp_run4_text,false) 
airp_run5_text=txt_add("Dimension","font:arial.ttf; size:16; color:#5599FF; halign:center;", 310, 480, 200, 20)visible(airp_run5_text,false) 
airp_run6_text=txt_add("Surface","font:arial.ttf; size:16; color:#5599FF; halign:center;", 420, 480, 200, 20)visible(airp_run6_text,false)

airp_nav1_text=txt_add("Navaids","font:ARIALI.TTF; size:18; color:white; halign:left;", 120, 645, 200, 20)visible(airp_nav1_text,false) 
airp_nav2_text=txt_add("RWY","font:arial.ttf; size:16; color:#5599FF; halign:left;", 120, 675, 200, 20)visible(airp_nav2_text,false) 
airp_nav3_text=txt_add("Direction","font:arial.ttf; size:16; color:#5599FF; halign:center;", 140, 675, 200, 20)visible(airp_nav3_text,false) 
airp_nav4_text=txt_add("ILS","font:arial.ttf; size:16; color:#5599FF; halign:center;", 290, 675, 200, 20)visible(airp_nav4_text,false)
airp_nav5_text=txt_add("PAPI","font:arial.ttf; size:16; color:#5599FF; halign:center;", 420, 675, 200, 20)visible(airp_nav5_text,false)


airapA_rwy_text1=txt_add("","font:arial.ttf; size:16; color:white; halign:left;", 120, 512, 200, 20)visible(airapA_rwy_text1,false)
airapA_rwy_text2=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 120, 512, 200, 20)visible(airapA_rwy_text2,false)
airapA_rwy_text3=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 200, 512, 200, 20)visible(airapA_rwy_text3,false)
airapA_rwy_text4=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 310, 512, 200, 20)visible(airapA_rwy_text4,false)
airapA_rwy_text5=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 420, 512, 200, 20)visible(airapA_rwy_text5,false)
airapA_rwy_text6=txt_add("","font:arial.ttf; size:16; color:white; halign:left;", 120, 532, 200, 20)visible(airapA_rwy_text6,false)
airapA_rwy_text7=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 120, 532, 200, 20)visible(airapA_rwy_text7,false)
airapA_rwy_text8=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 200, 532, 200, 20)visible(airapA_rwy_text8,false)
airapA_rwy_text9=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 310, 532, 200, 20)visible(airapA_rwy_text9,false)
airapA_rwy_text10=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 420, 532, 200, 20)visible(airapA_rwy_text10,false)
airapA_rwy_text11=txt_add("","font:arial.ttf; size:16; color:white; halign:left;", 120, 552, 200, 20)visible(airapA_rwy_text11,false)
airapA_rwy_text12=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 120, 552, 200, 20)visible(airapA_rwy_text12,false)
airapA_rwy_text13=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 200, 552, 200, 20)visible(airapA_rwy_text13,false)
airapA_rwy_text14=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 310, 552, 200, 20)visible(airapA_rwy_text14,false)
airapA_rwy_text15=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 420, 552, 200, 20)visible(airapA_rwy_text15,false)
airapA_rwy_text16=txt_add("","font:arial.ttf; size:16; color:white; halign:left;", 120, 572, 200, 20)visible(airapA_rwy_text16,false)
airapA_rwy_text17=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 120, 572, 200, 20)visible(airapA_rwy_text17,false)
airapA_rwy_text18=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 200, 572, 200, 20)visible(airapA_rwy_text18,false)
airapA_rwy_text19=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 310, 572, 200, 20)visible(airapA_rwy_text19,false)
airapA_rwy_text20=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 420, 572, 200, 20)visible(airapA_rwy_text20,false)
airapA_rwy_text21=txt_add("","font:arial.ttf; size:16; color:white; halign:left;", 120, 592, 200, 20)visible(airapA_rwy_text21,false)
airapA_rwy_text22=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 120, 592, 200, 20)visible(airapA_rwy_text22,false)
airapA_rwy_text23=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 200, 592, 200, 20)visible(airapA_rwy_text23,false)
airapA_rwy_text24=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 310, 592, 200, 20)visible(airapA_rwy_text24,false)
airapA_rwy_text25=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 420, 592, 200, 20)visible(airapA_rwy_text25,false)
airapA_rwy_text26=txt_add("","font:arial.ttf; size:16; color:white; halign:left;", 120, 612, 200, 20)visible(airapA_rwy_text26,false)
airapA_rwy_text27=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 120, 612, 200, 20)visible(airapA_rwy_text27,false)
airapA_rwy_text28=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 200, 612, 200, 20)visible(airapA_rwy_text28,false)
airapA_rwy_text29=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 310, 612, 200, 20)visible(airapA_rwy_text29,false)
airapA_rwy_text30=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 420, 612, 200, 20)visible(airapA_rwy_text30,false)

airapA_nav_text1=txt_add("","font:arial.ttf; size:16; color:white; halign:left;", 120, 712, 200, 20)visible(airapA_nav_text1,false)
airapA_nav_text2=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 140, 712, 200, 20)visible(airapA_nav_text2,false)
airapA_nav_text3=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 290, 712, 200, 20)visible(airapA_nav_text3,false) 
airapA_nav_text4=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 420, 712, 200, 20)visible(airapA_nav_text4,false) 
airapA_nav_text5=txt_add("","font:arial.ttf; size:16; color:white; halign:left;", 120, 732, 200, 20)visible(airapA_nav_text5,false)
airapA_nav_text6=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 140, 732, 200, 20)visible(airapA_nav_text6,false)
airapA_nav_text7=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 290, 732, 200, 20)visible(airapA_nav_text7,false) 
airapA_nav_text8=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 420, 732, 200, 20)visible(airapA_nav_text8,false) 
airapA_nav_text9=txt_add("","font:arial.ttf; size:16; color:white; halign:left;", 120, 752, 200, 20)visible(airapA_nav_text9,false)
airapA_nav_text10=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 140, 752, 200, 20)visible(airapA_nav_text10,false)
airapA_nav_text11=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 290, 752, 200, 20)visible(airapA_nav_text11,false) 
airapA_nav_text12=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 420, 752, 200, 20)visible(airapA_nav_text12,false) 
airapA_nav_text13=txt_add("","font:arial.ttf; size:16; color:white; halign:left;", 120, 772, 200, 20)visible(airapA_nav_text13,false)
airapA_nav_text14=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 140, 772, 200, 20)visible(airapA_nav_text14,false)
airapA_nav_text15=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 290, 772, 200, 20)visible(airapA_nav_text15,false) 
airapA_nav_text16=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 420, 772, 200, 20)visible(airapA_nav_text16,false)  
airapA_nav_text17=txt_add("","font:arial.ttf; size:16; color:white; halign:left;", 120, 792, 200, 20)visible(airapA_nav_text17,false)
airapA_nav_text18=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 140, 792, 200, 20)visible(airapA_nav_text18,false)
airapA_nav_text19=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 290, 792, 200, 20)visible(airapA_nav_text19,false) 
airapA_nav_text20=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 420, 792, 200, 20)visible(airapA_nav_text20,false) 
airapA_nav_text21=txt_add("","font:arial.ttf; size:16; color:white; halign:left;", 120, 812, 200, 20)visible(airapA_nav_text21,false)
airapA_nav_text22=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 140, 812, 200, 20)visible(airapA_nav_text22,false)
airapA_nav_text23=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 290, 812, 200, 20)visible(airapA_nav_text23,false) 
airapA_nav_text24=txt_add("","font:arial.ttf; size:16; color:white; halign:center;", 420, 812, 200, 20)visible(airapA_nav_text24,false)  
 
arip_info2_group=group_add(airp1A_text_group,freq_menu_id,airp_info_canvas2_group,airp_run1_text,airp_run2_text,airp_run3_text,airp_run4_text,airp_run5_text,airp_run6_text,airp_nav1_text,airp_nav2_text,airp_nav3_text,airp_nav4_text,airp_nav5_text,airapA_rwy_text1,airapA_rwy_text2,airapA_rwy_text3,airapA_rwy_text4,airapA_rwy_text5,airapA_rwy_text6,airapA_rwy_text7,airapA_rwy_text8,airapA_rwy_text9,airapA_rwy_text10,airapA_rwy_text11,airapA_rwy_text12,airapA_rwy_text13,airapA_rwy_text14,airapA_rwy_text15,airapA_rwy_text16,airapA_rwy_text17,airapA_rwy_text18,airapA_rwy_text19,airapA_rwy_text20,airapA_rwy_text21,airapA_rwy_text22,airapA_rwy_text23,airapA_rwy_text24,airapA_rwy_text25,airapA_rwy_text26,airapA_rwy_text27,airapA_rwy_text28,airapA_rwy_text29,airapA_rwy_text30,airapA_nav_text1,airapA_nav_text2,airapA_nav_text3,airapA_nav_text4,airapA_nav_text5,airapA_nav_text6,airapA_nav_text7,airapA_nav_text8,airapA_nav_text9,airapA_nav_text10,airapA_nav_text11,airapA_nav_text12,airapA_nav_text13,airapA_nav_text14,airapA_nav_text15,airapA_nav_text16,airapA_nav_text17,airapA_nav_text18,airapA_nav_text19,airapA_nav_text20,airapA_nav_text21,airapA_nav_text22,airapA_nav_text23,airapA_nav_text24)visible(arip_info2_group,false)

--====================================================================================================================================================--
--============================================== END OF AIRPORT INFO MENU 2 ==========================================================================--
--====================================================================================================================================================--


The values come from the static_data_load come from here.

Code: Select all

if iaco_var~=nil then

static_data_load("airports.json", function(data)

	if json1_data ~= nil then

	txt_set(chart_text, data[iaco_var]["NEAR AIRP"]["ICAO1"][1])	
	txt_set(chart_text1, data[iaco_var]["NEAR AIRP"]["ICAO1"][2])
	txt_set(chart_text2, data[iaco_var]["NEAR AIRP"]["ICAO1"][4])
	txt_set(chart_text2x, data[iaco_var]["NEAR AIRP"]["ICAO1"][3])
	
	txt_set(chart_text3, data[iaco_var]["NEAR AIRP"]["ICAO2"][1])	
	txt_set(chart_text4, data[iaco_var]["NEAR AIRP"]["ICAO2"][2])
	txt_set(chart_text5, data[iaco_var]["NEAR AIRP"]["ICAO2"][4])
	txt_set(chart_text5x, data[iaco_var]["NEAR AIRP"]["ICAO2"][3])	
	txt_set(chart_text6, data[iaco_var]["NEAR AIRP"]["ICAO3"][1])	
	txt_set(chart_text7, data[iaco_var]["NEAR AIRP"]["ICAO3"][2])
	txt_set(chart_text8, data[iaco_var]["NEAR AIRP"]["ICAO3"][4])
	txt_set(chart_text8x, data[iaco_var]["NEAR AIRP"]["ICAO3"][3])	
	txt_set(chart_text9, data[iaco_var]["NEAR AIRP"]["ICAO4"][1])	
	txt_set(chart_text10, data[iaco_var]["NEAR AIRP"]["ICAO4"][2])
	txt_set(chart_text11, data[iaco_var]["NEAR AIRP"]["ICAO4"][4])
	txt_set(chart_text11x, data[iaco_var]["NEAR AIRP"]["ICAO4"][3])	
	txt_set(chart_text12, data[iaco_var]["NEAR AIRP"]["ICAO5"][1])	
	txt_set(chart_text13, data[iaco_var]["NEAR AIRP"]["ICAO5"][2])
	txt_set(chart_text14, data[iaco_var]["NEAR AIRP"]["ICAO5"][4])
	txt_set(chart_text14x, data[iaco_var]["NEAR AIRP"]["ICAO5"][3])	
	

	txt_set(chart_text15, data[iaco_var]["NEAR NAV"]["ID1"][1])	
	txt_set(chart_text16, data[iaco_var]["NEAR NAV"]["ID1"][2])
	txt_set(chart_text17, data[iaco_var]["NEAR NAV"]["ID1"][3])
	txt_set(chart_text18, data[iaco_var]["NEAR NAV"]["ID1"][4])	
	txt_set(chart_text19, data[iaco_var]["NEAR NAV"]["ID1"][5])
	txt_set(chart_text20, data[iaco_var]["NEAR NAV"]["ID1"][6])	
	txt_set(chart_text21, data[iaco_var]["NEAR NAV"]["ID2"][1])	
	txt_set(chart_text22, data[iaco_var]["NEAR NAV"]["ID2"][2])
	txt_set(chart_text23, data[iaco_var]["NEAR NAV"]["ID2"][3])	
	txt_set(chart_text24, data[iaco_var]["NEAR NAV"]["ID2"][4])	
	txt_set(chart_text25, data[iaco_var]["NEAR NAV"]["ID2"][5])
	txt_set(chart_text26, data[iaco_var]["NEAR NAV"]["ID2"][6])	
	txt_set(chart_text27, data[iaco_var]["NEAR NAV"]["ID3"][1])	
	txt_set(chart_text28, data[iaco_var]["NEAR NAV"]["ID3"][2])
	txt_set(chart_text29, data[iaco_var]["NEAR NAV"]["ID3"][3])	
	txt_set(chart_text30, data[iaco_var]["NEAR NAV"]["ID3"][4])	
	txt_set(chart_text31, data[iaco_var]["NEAR NAV"]["ID3"][5])
	txt_set(chart_text32, data[iaco_var]["NEAR NAV"]["ID3"][6])
	txt_set(chart_text33, data[iaco_var]["NEAR NAV"]["ID4"][1])	
	txt_set(chart_text34, data[iaco_var]["NEAR NAV"]["ID4"][2])
	txt_set(chart_text35, data[iaco_var]["NEAR NAV"]["ID4"][3])	
	txt_set(chart_text36, data[iaco_var]["NEAR NAV"]["ID4"][4])	
	txt_set(chart_text37, data[iaco_var]["NEAR NAV"]["ID4"][5])
	txt_set(chart_text38, data[iaco_var]["NEAR NAV"]["ID4"][6])	
	txt_set(chart_text39, data[iaco_var]["NEAR NAV"]["ID5"][1])	
	txt_set(chart_text40, data[iaco_var]["NEAR NAV"]["ID5"][2])
	txt_set(chart_text41, data[iaco_var]["NEAR NAV"]["ID5"][3])	
	txt_set(chart_text42, data[iaco_var]["NEAR NAV"]["ID5"][4])	
	txt_set(chart_text43, data[iaco_var]["NEAR NAV"]["ID5"][5])
	txt_set(chart_text44, data[iaco_var]["NEAR NAV"]["ID5"][6])

	txt_set(chartA_text, data[iaco_var]["AIRPORT"]["INDENT"])		
	txt_set(airpA_text1,data[iaco_var]["AIRPORT"]["NAME"])
	txt_set(airpA_text2,data[iaco_var]["AIRPORT"]["AREA"])	
	txt_set(airpA_text3,data[iaco_var]["AIRPORT"]["POSITION"])	
	txt_set(airpA_text4,data[iaco_var]["AIRPORT"]["ELIVATION"])
	txt_set(airpA_text7,data[iaco_var]["AIRPORT"]["MAGVAR"])	
	txt_set(airpA_text9,data[iaco_var]["AIRPORT"]["IFR"])
	txt_set(airpA_text11,data[iaco_var]["AIRPORT"]["ARP TYPE"])	
	txt_set(airpA_text13,data[iaco_var]["AIRPORT"]["LONG RWY"])
	
	txt_set(airapA_frq_text1,data[iaco_var]["COM"]["COM1"][1])
	txt_set(airapA_frq_text2,data[iaco_var]["COM"]["COM1"][2])
	txt_set(airapA_frq_text3,data[iaco_var]["COM"]["COM1"][3])
	txt_set(airapA_frq_text4,data[iaco_var]["COM"]["COM1"][4])	
	txt_set(airapA_frq_text5,data[iaco_var]["COM"]["COM2"][1])
	txt_set(airapA_frq_text6,data[iaco_var]["COM"]["COM2"][2])
	txt_set(airapA_frq_text7,data[iaco_var]["COM"]["COM2"][3])
	txt_set(airapA_frq_text8,data[iaco_var]["COM"]["COM2"][4])
	txt_set(airapA_frq_text9,data[iaco_var]["COM"]["COM3"][1])
	txt_set(airapA_frq_text10,data[iaco_var]["COM"]["COM3"][2])
	txt_set(airapA_frq_text11,data[iaco_var]["COM"]["COM3"][3])
	txt_set(airapA_frq_text12,data[iaco_var]["COM"]["COM3"][4])	
	txt_set(airapA_frq_text13,data[iaco_var]["COM"]["COM4"][1])
	txt_set(airapA_frq_text14,data[iaco_var]["COM"]["COM4"][2])
	txt_set(airapA_frq_text15,data[iaco_var]["COM"]["COM4"][3])
	txt_set(airapA_frq_text16,data[iaco_var]["COM"]["COM4"][4])	
	txt_set(airapA_frq_text17,data[iaco_var]["COM"]["COM5"][1])
	txt_set(airapA_frq_text18,data[iaco_var]["COM"]["COM5"][2])
	txt_set(airapA_frq_text19,data[iaco_var]["COM"]["COM5"][3])
	txt_set(airapA_frq_text20,data[iaco_var]["COM"]["COM5"][4])	
	txt_set(airapA_frq_text21,data[iaco_var]["COM"]["COM6"][1])
	txt_set(airapA_frq_text22,data[iaco_var]["COM"]["COM6"][2])
	txt_set(airapA_frq_text23,data[iaco_var]["COM"]["COM6"][3])
	txt_set(airapA_frq_text24,data[iaco_var]["COM"]["COM6"][4])		
	txt_set(airapA_frq_text25,data[iaco_var]["COM"]["COM7"][1])
	txt_set(airapA_frq_text26,data[iaco_var]["COM"]["COM7"][2])
	txt_set(airapA_frq_text27,data[iaco_var]["COM"]["COM7"][3])
	txt_set(airapA_frq_text28,data[iaco_var]["COM"]["COM7"][4])	
	txt_set(airapA_frq_text29,data[iaco_var]["COM"]["COM8"][1])
	txt_set(airapA_frq_text30,data[iaco_var]["COM"]["COM8"][2])
	txt_set(airapA_frq_text31,data[iaco_var]["COM"]["COM8"][3])
	txt_set(airapA_frq_text32,data[iaco_var]["COM"]["COM8"][4])
	txt_set(airapA_frq_text33,data[iaco_var]["COM"]["COM9"][1])
	txt_set(airapA_frq_text34,data[iaco_var]["COM"]["COM9"][2])
	txt_set(airapA_frq_text35,data[iaco_var]["COM"]["COM9"][3])
	txt_set(airapA_frq_text36,data[iaco_var]["COM"]["COM9"][4])	
	txt_set(airapA_frq_text37,data[iaco_var]["COM"]["COM10"][1])
	txt_set(airapA_frq_text38,data[iaco_var]["COM"]["COM10"][2])
	txt_set(airapA_frq_text39,data[iaco_var]["COM"]["COM10"][3])
	txt_set(airapA_frq_text40,data[iaco_var]["COM"]["COM10"][4])
	txt_set(airapA_frq_text41,data[iaco_var]["COM"]["COM11"][1])
	txt_set(airapA_frq_text42,data[iaco_var]["COM"]["COM11"][2])
	txt_set(airapA_frq_text43,data[iaco_var]["COM"]["COM11"][3])
	txt_set(airapA_frq_text44,data[iaco_var]["COM"]["COM11"][4])	
	txt_set(airapA_frq_text45,data[iaco_var]["COM"]["COM12"][1])
	txt_set(airapA_frq_text46,data[iaco_var]["COM"]["COM12"][2])
	txt_set(airapA_frq_text47,data[iaco_var]["COM"]["COM12"][3])
	txt_set(airapA_frq_text48,data[iaco_var]["COM"]["COM12"][4])	
	txt_set(airapA_frq_text49,data[iaco_var]["COM"]["COM13"][1])
	txt_set(airapA_frq_text50,data[iaco_var]["COM"]["COM13"][2])
	txt_set(airapA_frq_text51,data[iaco_var]["COM"]["COM13"][3])
	txt_set(airapA_frq_text52,data[iaco_var]["COM"]["COM13"][4])	
	txt_set(airapA_frq_text53,data[iaco_var]["COM"]["COM14"][1])
	txt_set(airapA_frq_text54,data[iaco_var]["COM"]["COM14"][2])
	txt_set(airapA_frq_text55,data[iaco_var]["COM"]["COM14"][3])
	txt_set(airapA_frq_text56,data[iaco_var]["COM"]["COM14"][4])	
	txt_set(airapA_frq_text57,data[iaco_var]["COM"]["COM15"][1])
	txt_set(airapA_frq_text58,data[iaco_var]["COM"]["COM15"][2])
	txt_set(airapA_frq_text59,data[iaco_var]["COM"]["COM15"][3])
	txt_set(airapA_frq_text60,data[iaco_var]["COM"]["COM15"][4])	
	txt_set(airapA_frq_text61,data[iaco_var]["COM"]["COM16"][1])
	txt_set(airapA_frq_text62,data[iaco_var]["COM"]["COM16"][2])
	txt_set(airapA_frq_text63,data[iaco_var]["COM"]["COM16"][3])
	txt_set(airapA_frq_text64,data[iaco_var]["COM"]["COM16"][4])		
	txt_set(airapA_frq_text65,data[iaco_var]["COM"]["COM17"][1])
	txt_set(airapA_frq_text66,data[iaco_var]["COM"]["COM17"][2])
	txt_set(airapA_frq_text67,data[iaco_var]["COM"]["COM17"][3])
	txt_set(airapA_frq_text68,data[iaco_var]["COM"]["COM17"][4])	
	
	txt_set(airapA_rwy_text1,data[iaco_var]["RWY"]["RWY1"][1])
	txt_set(airapA_rwy_text2,data[iaco_var]["RWY"]["RWY1"][2])	
	txt_set(airapA_rwy_text3,data[iaco_var]["RWY"]["RWY1"][3])	
	txt_set(airapA_rwy_text4,data[iaco_var]["RWY"]["RWY1"][4])
	txt_set(airapA_rwy_text5,data[iaco_var]["RWY"]["RWY1"][5])
	txt_set(airapA_rwy_text6,data[iaco_var]["RWY"]["RWY2"][1])
	txt_set(airapA_rwy_text7,data[iaco_var]["RWY"]["RWY2"][2])	
	txt_set(airapA_rwy_text8,data[iaco_var]["RWY"]["RWY2"][3])	
	txt_set(airapA_rwy_text9,data[iaco_var]["RWY"]["RWY2"][4])
	txt_set(airapA_rwy_text10,data[iaco_var]["RWY"]["RWY2"][5])
	txt_set(airapA_rwy_text11,data[iaco_var]["RWY"]["RWY3"][1])
	txt_set(airapA_rwy_text12,data[iaco_var]["RWY"]["RWY3"][2])	
	txt_set(airapA_rwy_text13,data[iaco_var]["RWY"]["RWY3"][3])	
	txt_set(airapA_rwy_text14,data[iaco_var]["RWY"]["RWY3"][4])
	txt_set(airapA_rwy_text15,data[iaco_var]["RWY"]["RWY3"][5])
	txt_set(airapA_rwy_text16,data[iaco_var]["RWY"]["RWY4"][1])
	txt_set(airapA_rwy_text17,data[iaco_var]["RWY"]["RWY4"][2])	
	txt_set(airapA_rwy_text18,data[iaco_var]["RWY"]["RWY4"][3])	
	txt_set(airapA_rwy_text19,data[iaco_var]["RWY"]["RWY4"][4])
	txt_set(airapA_rwy_text20,data[iaco_var]["RWY"]["RWY4"][5])	
	txt_set(airapA_rwy_text21,data[iaco_var]["RWY"]["RWY5"][1])
	txt_set(airapA_rwy_text22,data[iaco_var]["RWY"]["RWY5"][2])	
	txt_set(airapA_rwy_text23,data[iaco_var]["RWY"]["RWY5"][3])	
	txt_set(airapA_rwy_text24,data[iaco_var]["RWY"]["RWY5"][4])
	txt_set(airapA_rwy_text25,data[iaco_var]["RWY"]["RWY5"][5])
	txt_set(airapA_rwy_text26,data[iaco_var]["RWY"]["RWY6"][1])
	txt_set(airapA_rwy_text27,data[iaco_var]["RWY"]["RWY6"][2])	
	txt_set(airapA_rwy_text28,data[iaco_var]["RWY"]["RWY6"][3])	
	txt_set(airapA_rwy_text29,data[iaco_var]["RWY"]["RWY6"][4])
	txt_set(airapA_rwy_text30,data[iaco_var]["RWY"]["RWY6"][5])
	
	txt_set(airapA_nav_text1,data[iaco_var]["NAV"]["RWY1"][1])
	txt_set(airapA_nav_text2,data[iaco_var]["NAV"]["RWY1"][2])	
	txt_set(airapA_nav_text3,data[iaco_var]["NAV"]["RWY1"][3])	
	txt_set(airapA_nav_text4,data[iaco_var]["NAV"]["RWY1"][4])	
	txt_set(airapA_nav_text5,data[iaco_var]["NAV"]["RWY2"][1])
	txt_set(airapA_nav_text6,data[iaco_var]["NAV"]["RWY2"][2])	
	txt_set(airapA_nav_text7,data[iaco_var]["NAV"]["RWY2"][3])	
	txt_set(airapA_nav_text8,data[iaco_var]["NAV"]["RWY2"][4])	
	txt_set(airapA_nav_text9,data[iaco_var]["NAV"]["RWY3"][1])
	txt_set(airapA_nav_text10,data[iaco_var]["NAV"]["RWY3"][2])	
	txt_set(airapA_nav_text11,data[iaco_var]["NAV"]["RWY3"][3])	
	txt_set(airapA_nav_text12,data[iaco_var]["NAV"]["RWY3"][4])	
	txt_set(airapA_nav_text13,data[iaco_var]["NAV"]["RWY4"][1])
	txt_set(airapA_nav_text14,data[iaco_var]["NAV"]["RWY4"][2])	
	txt_set(airapA_nav_text15,data[iaco_var]["NAV"]["RWY4"][3])	
	txt_set(airapA_nav_text16,data[iaco_var]["NAV"]["RWY4"][4])
	txt_set(airapA_nav_text17,data[iaco_var]["NAV"]["RWY5"][1])
	txt_set(airapA_nav_text18,data[iaco_var]["NAV"]["RWY5"][2])	
	txt_set(airapA_nav_text19,data[iaco_var]["NAV"]["RWY5"][3])	
	txt_set(airapA_nav_text20,data[iaco_var]["NAV"]["RWY5"][4])	
	txt_set(airapA_nav_text21,data[iaco_var]["NAV"]["RWY6"][1])
	txt_set(airapA_nav_text22,data[iaco_var]["NAV"]["RWY6"][2])	
	txt_set(airapA_nav_text23,data[iaco_var]["NAV"]["RWY6"][3])	
	txt_set(airapA_nav_text24,data[iaco_var]["NAV"]["RWY6"][4])

	print(data["iaco_var"])
	end

	
end)

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: Keith's LUA Help thread.

#8 Post by Sling »

Keith Baxter wrote: Thu Nov 15, 2018 9:30 am Thank you Tony,

That looks really simple.

Because each hardware function can do multiple things I take it that that code can be put in an if statement like this.
Essentially yes but there may be an even simpler way. I don't know what that may be without understanding your hardware related variables such as map_button, chart_button and any others that need to be considered.

What you can do is include everything that has a controlling interest in the visibility state into the logic. It just needs to eventually equate to a true or false like this.

visible(some_grp, mini_tile_left == 1 and map_button == 2 and chart_button > 0 and something_else < 4)

You can mix the and's with or's if you need it, as long as the final logic result is a true or false. You get the idea.

Tony

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

Re: Keith's LUA Help thread.

#9 Post by Sling »

Keith Baxter wrote: Thu Nov 15, 2018 9:59 am Am I doing this correctly ? It works but I think there is an easier way.
This would be a lot less code if done in a loop. The criteria hear is if you start to repeat code then put it in a loop and do it however many times you need.

If the code is made to allow for variations you can feed the variations in using either logic or an array. You just need to figure out the most efficient method for the variation.

Example: I want to do 20 txt_add's. They only use 2 different font's, 3 different sizes but everyone is in a different y location but evenly spaced.

I could do something like

Code: Select all

for i=1, 20 do

font_type = "arial.ttf"

if (i < 3 or i ==8) then
	font_type = "ARIALI.TTF"
	font_size = 18
elseif (i % 4 == 0) then
	font_size = 16
else
	font_size = 12
end

txt_add("", "font:" .. font_type .. "; size:" .. font_size .. "px; color:white; halign:left;", 118, 428 + i * 22, 200, 30)

end 

It a little harder to get your head round which is why comments are so important. The more lines of similar code you repeat the more efficient this method becomes. Just imagine generating a phone directory line by line or with just a loop that gets the relevant info from a database or file and just repeats the process for as many iterations as you need.

I haven't tested the example code by the way but I hope it helps explain the rationale.

Tony

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

Re: Keith's LUA Help thread.

#10 Post by Keith Baxter »

Tony,

This is what the current MAP button looks like.

the map button has 3 indents.

1 shows the map tile 3
2 shows the map tiles 3&4
3 shows the map tile 4

Now the map module has three sub modules

1 is the ND
2 is the map
3 is the charts

these sub modules are selected by turning an encoder.

Each sub menu has a multiple of pages. These pages are selected by one of the 5 buttons on the side of the instrument.

Anyway here is a start of the map button function.

Code: Select all

function button_map() 

map_module_button = map_module_button +1
if (map_module_button > 3) then map_module_button = 1 end	
	print("BEFORE====BEFORE====BEFORE====BEFORE====BEFORE====BEFORE====BEFORE====BEFORE","The MAP MODULE button was pressed",map_module_button,"FMS MODULE BUTTON", fms_module_button,"CKLST MODULE BUTTON",cklst_module_button,"SYS MODULE BUTTON",sys_module_button,"RADIO MODULE BUTTON",radio_module_button)	
---map module---
	if map_module_button==1 then 

---move modules occupying position 1 to position 3
	---fms module---
		if fms_module_button ==1 or fms_module_button ==2 then
		map_module_button=1 fms_module_button =3 cklst_module_button=0 sys_module_button=0 radio_module_button=0
		map_blue_mrk_L = 2
		visible(fms_menu_bR,true)visible(fms_men_1_group_rs,true)visible(fms_actv_rs_group,true)visible(fms_actv_rs_menu_title,true)visible(fms_active_rs_marker_group1,true)visible(fms_actv_rs_sml_scroll_fence,true)visible(fms_rbm1,true)
		viewport_rect(fms_actv_rs_sml_scroll_fence, 610, 444, 500, 424)
		viewport_rect(fms_actv_rs_group, 610, 444, 500, 420)		
		visible(map_menu_bL,true) visible(mapL_men_l_grp,true)
	---cklst module---		
		elseif cklst_module_button ==1 or cklst_module_button ==2  then
		map_module_button=1 fms_module_button =0 cklst_module_button=3 sys_module_button=0 radio_module_button=0
			
		visible(cklst_menu_bR,true)visible(cklst_main_rs_menu_group,true)visible(cklst_rbm1,true)
		
	---sys module---	
		elseif sys_module_button ==1 or sys_module_button ==2 then
		map_module_button=1 fms_module_button =0 cklst_module_button=0 sys_module_button=3 radio_module_button=0
		
		visible(sys_menu_bR,true) visible(sys_rbm1,true)
	---radio module---
		elseif radio_module_button ==1 or radio_module_button ==2 then
		map_module_button=1 fms_module_button =0 cklst_module_button=0 sys_module_button=0 radio_module_button=3		
		
		visible(map_menu_bL,true) visible(mapL_men_l_grp,true)
		end
---show map position 1---		
					visible(map_menu_bL,true)visible(map_lbm2,true)visible(mapL_men_l_grp,true)
					visible(navmap,true)visible(airplane_icon,true)
					viewport_rect(navmap, 100, 408, 498, 450)	
					move(navmap, -390, -36,990,890)
					move(zoom_legend_grp,465,822,130,36)
					move(loc_legend_grp,272,822,190,36)
					move(nexrad_grp,550,410,45,300)				
					move(airmet_legend_grp,435,720,160,90)	
					move(wind_legend_grp, 100,410,200,325)
					move(ages_legend_grp,100,610,160,80)
					move(xm_scroll_group,1,nil,1,1)		
---map module---
	elseif map_module_button==2 then
---hide modules occupying position 1 and 2 	
	visible(KILL_ALL,false)visible(navmap,false)visible(airplane_icon,false)	
	---fms module---
		if fms_module_button ==3 then
		map_module_button=2 fms_module_button =4 cklst_module_button=0 sys_module_button=0 radio_module_button=0		
	---cklst module---
		elseif cklst_module_button ==3 then
		map_module_button=2 fms_module_button =0 cklst_module_button=4 sys_module_button=0 radio_module_button=0

	---sys module---	
		elseif sys_module_button ==3  then
		map_module_button=2 fms_module_button =0 cklst_module_button=0 sys_module_button=4 radio_module_button=0			
	---radio module---
		elseif radio_module_button ==3 then
		map_module_button=2 fms_module_button =0 cklst_module_button=0 sys_module_button=0 radio_module_button=4		
		end
---show map position 2---			
					visible(map_menu_bL,true)visible(map_lbm2,true)visible(mapL_men_l_grp,true)	
					visible(map_menu_bR,true)visible(map_rbm2,true)visible(mapR_men_l_grp,true)
					visible(navmap,true)visible(airplane_icon, true)	
					viewport_rect(navmap, 100, 408, 1000, 450)
					move(navmap, -900, -36,2000,890)
					move(zoom_legend_grp,965,822,130,36)		
					move(loc_legend_grp,772,822,190,36)		
					move(nexrad_grp,1055,410,45,300)
					move(airmet_legend_grp,935,720,160,90)				
					move(wind_legend_grp, 100,410,200,325)
					move(ages_legend_grp,100,610,160,80)
					move(xm_scroll_group,1,nil,1,1)						
---map module---
	elseif map_module_button==3 then
---move modules occupying position 3 to 1 	
	visible(KILL_ALL,false)visible(navmap,false)visible(airplane_icon,false)	
	---fms module---
		if fms_module_button ==4then
		map_module_button=3 fms_module_button =1 cklst_module_button=0 sys_module_button=0 radio_module_button=0		 
	
		visible(fms_menu_bL,true)visible(fms_men_1_group_ls,true)visible(fms_actv_ls_group,true)visible(fms_actv_ls_menu_title,true)visible(fms_active_ls_marker_group1,true)visible(fms_actv_ls_sml_scroll_fence,true)visible(fms_lbm1,true)				
		viewport_rect(fms_actv_ls_sml_scroll_fence, 100, 444, 500, 424)	
		viewport_rect(fms_actv_ls_group, 100, 444, 500, 420)
	---cklst module---
		elseif cklst_module_button ==4 then
		map_module_button=3 fms_module_button =0 cklst_module_button=1 sys_module_button=0 radio_module_button=0		

		visible(cklst_menu_bL,true)visible(cklst_main_ls_menu_group,true)visible(cklst_lbm1,true)
	---sys module---	
		elseif sys_module_button ==4  then
		map_module_button=3 fms_module_button =0 cklst_module_button=0 sys_module_button=1 radio_module_button=0

		visible(sys_menu_bL,true) visible(sys_lbm1,true)		
	---radio module---
		elseif radio_module_button ==4 then
		map_module_button=3 fms_module_button =0 cklst_module_button=0 sys_module_button=0 radio_module_button=1		

		end
---show map position 3---		
					visible(map_menu_bR,true)visible(map_rbm2,true)visible(mapR_men_l_grp,true)
					visible(navmap,true)visible(airplane_icon, true)
					viewport_rect(navmap, 600, 408, 498, 450)
					move(navmap, 100, 404,995,890)
					move(zoom_legend_grp,965,822,130,36)
					move(loc_legend_grp,772,822,190,36)
					move(nexrad_grp,1050,410,45,300)				
					move(airmet_legend_grp,935,720,160,90)	
					move(wind_legend_grp, 602,410,200,325)
					move(ages_legend_grp,602,610,160,80)
					move(xm_scroll_group,1,nil,1,1)	

		
	end	
print("AFTER=====AFTER=====AFTER=====AFTER=====AFTER=====AFTER=====AFTER=====AFTER","The MAP MODULE button was pressed",map_module_button,"FMS MODULE BUTTON", fms_module_button,"CKLST MODULE BUTTON",cklst_module_button,"SYS MODULE BUTTON",sys_module_button,"RADIO MODULE BUTTON",radio_module_button)	
end
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 

Post Reply