nav_get question

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Message
Author
Shimokuta
Posts: 113
Joined: Wed Feb 03, 2021 12:52 pm

nav_get question

#1 Post by Shimokuta »

I am coding my FMS for the Lear 45 .
For that i am using the nav_get option to get the runway information.
I read an ICAO from a table created with airac data information.
I then fill a local table with runway info.
It seems the table is lost (table size is 0) when returning out of the function of nav get data; LUA code continues with empty table
i think i can workaround this, but what is the way to go with this?

Code: Select all

local Runway_available = {}
runway_screen = canvas_add(10,60,300,530)
 
function data_runways(runways)
  if runways ~= nil then
   
    for i=1, #runways do
	  table.insert(Runway_available ,runways[i]["NAME"])
	  print(Runway_available[i])
    end
  else
    print("Error while querying nav data")
  end
 
 canvas_draw(runway_screen, function()
	
		if #Runway_available ~= nil then 
			if #Runway_available <= 8 then
				for i = 1, #Runway_available do		
					
					--print to canvas
				end
			end
		
		end
	end)

  for i = 1, #Runway_available do		
					
	print(Runway_available[i])
end
end


function data_airports(airports)
  if airports ~= nil then
    -- Print the found airports to log
    for i=1, #airports do
	  airportid = airports[i]["ID"]
	  nav_get("RUNWAY", "AIRPORT_ID", airportid, data_runways)
	  
    end
  else
    print("Error while querying nav data")
  end
 
end


nav_get("AIRPORT", "ICAO", "EHEH", data_airports)

print(#Runway_available)

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

Re: nav_get question

#2 Post by SimPassion »

There's two print statements, so it displays result twice in the console, however it works
We just have the ensure the sim is running, otherwise it wouldn't
Here with your EHEH sample and AM 4.2 Beta 15

image.png

Shimokuta
Posts: 113
Joined: Wed Feb 03, 2021 12:52 pm

Re: nav_get question

#3 Post by Shimokuta »

Yes , i know , but as you can see the number of records show 0, and this is at the top of the console, runway information is printed from within functions
This means there is nothing returned from the functions…
The same print action after the nav_get command results in an 0 result

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

Re: nav_get question

#4 Post by SimPassion »

Shimokuta wrote: Sun May 28, 2023 10:07 am Yes , i know , but as you can see the number of records show 0, and this is at the top of the console, runway information is printed from within functions
This means there is nothing returned from the functions…
The same print action after the nav_get command results in an 0 result
No, this is the print outside function which gives 0 before any function was running at least once
you'll just have to figure out how events occurs through time
the best would be to print at the end and within the function itself

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

Re: nav_get question

#5 Post by SimPassion »

Ok, it could be I'm wrong
The count # may rely on numeric values only through indices, I have to check to confirm. If this statement is correct, having strings field may trigger this unexpected 0 result ... See next ...

[EDIT] Not confirmed, it works in both case, so false track ...
I have to investigate a bit further

Code: Select all

local Runway_available = {1,2}
print(#Runway_available)

local Runway_available = {"RW03","RW21"}
print(#Runway_available)
image.png
image.png (3.55 KiB) Viewed 602 times

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

Re: nav_get question

#6 Post by SimPassion »

Though I hadn't checked properly previously, my first statement was the good one
Please check with this :

Code: Select all

--====================================================================================
--								CHECK PURPOSE
--====================================================================================

local Runway_available = {}
runway_screen = canvas_add(10,60,300,530)
 
function data_runways(runways)
  if runways ~= nil then
   
    for i=1, #runways do
	  table.insert(Runway_available ,runways[i]["NAME"])
	  -- print(Runway_available[i])
    end
  else
    print("Error while querying nav data")
  end
 	print(#Runway_available)

 canvas_draw(runway_screen, function()
	
		if #Runway_available ~= nil then 
			if #Runway_available <= 8 then
				for i = 1, #Runway_available do		
					
					--print to canvas
				end
			end
		
		end
	end)

  for i = 1, #Runway_available do		
					
	print(Runway_available[i])
	end
	
	print(#Runway_available)
	
end


function data_airports(airports)
  if airports ~= nil then
    -- Print the found airports to log
    for i=1, #airports do
	  airportid = airports[i]["ID"]
	  nav_get("RUNWAY", "AIRPORT_ID", airportid, data_runways)
	  
    end
  else
    print("Error while querying nav data")
  end
end

function launch()
	nav_get("AIRPORT", "ICAO", "LFLS", data_airports)
	print(#Runway_available)
end

launch()

Shimokuta
Posts: 113
Joined: Wed Feb 03, 2021 12:52 pm

Re: nav_get question

#7 Post by Shimokuta »

No this also does not work. :(
I tried this for my original code and there is found this issue.

THere are some more print statements in the functions maybe that confused you?
if you leave them out en only print the #Runway_available in the launch() function then this results also in a 0 record.

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

Re: nav_get question

#8 Post by SimPassion »

Shimokuta wrote: Sun May 28, 2023 3:45 pm No this also does not work. :(
I tried this for my original code and there is found this issue.

THere are some more print statements in the functions maybe that confused you?
if you leave them out en only print the #Runway_available in the launch() function then this results also in a 0 record.
It just works fine using another ICAO with your code where I've only added print statement at the proper place and nothing more, as you see here (the whole script is already available in my last previous post) :

image.png

Shimokuta
Posts: 113
Joined: Wed Feb 03, 2021 12:52 pm

Re: nav_get question

#9 Post by Shimokuta »

The first 0 you see in the output box is in fact the one you start in the function what starts the nav_get command the other one are from the other functions.
It doesn’t matter what icao you use

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

Re: nav_get question

#10 Post by SimPassion »

Shimokuta wrote: Sun May 28, 2023 6:24 pm The first 0 you see in the output box is in fact the one you start in the function what starts the nav_get command the other one are from the other functions.
It doesn’t matter what icao you use

Code: Select all

function launch()
	nav_get("AIRPORT", "ICAO", "LFLS", data_airports)
	print(#Runway_available)
end

launch()
As you can see the print which report 0 is made outside the "nav_get" callback, whereas the print which are inside the callback functions are working properly, please pay attention to this and try also to get it in the way it works

Post Reply