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

Re: nav_get question

#11 Post by Shimokuta »

Yes, but that was my issue ;)
Why is the table not persistent outside the nav_get function?

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

Re: nav_get question

#12 Post by SimPassion »

Shimokuta wrote: Sun May 28, 2023 7:18 pm Yes, but that was my issue ;)
Why is the table not persistent outside the nav_get function?
Because we have to init it with arbitrary values at first
Let's try with for example (have to know the world max runway number on any airport for your goal) :

Code: Select all

local Runway_available = {"","","","","","","","","",""}

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

Re: nav_get question

#13 Post by Shimokuta »

I think the behaviour is by design.
It seems not to be possible to use nav data in local variables.
In attached code i simply created 2 local variables rw 1 and rw 2 and fill these in the nav_get function.
They also are not persistent further in the main code.
I think the nav_get features are merely designed for use in maps not for the purpose i was thinking of.
Maybe @Ralph or @CorJan can clarify this.?
I think i will use Airac Navdata to read runway information .

Code: Select all

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

local Runway_available = {}
local rw1 = ""
local rw2 = ""
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"])
	  rw1 = runways[1]["NAME"]
	  rw2 = runways[2]["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)
	print("Runway records in function " .. #Runway_available)
	print("rw local var1 in function : " ..rw1)
	print("rw local var2 in function : " ..rw2)
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", "EHEH", data_airports)
	print("Runway records in main " .. #Runway_available)
	print("rw local var1 : " ..rw1)
	print("rw local var2 : " ..rw2)
end

launch()

User avatar
Corjan
Posts: 2936
Joined: Thu Nov 19, 2015 9:04 am

Re: nav_get question

#14 Post by Corjan »

Hi,


Maybe I'm missing something, but you should be able to store the runways in a global variable.

Something like this:

Code: Select all

global_runways = nil
nav_get("RUNWAY", "AIRPORT_ID", "12", function(runways)
	global_runways = runways
end)

timer_start(0, 1000, function()
	print("runways obj: " .. tostring(global_runways))
end)
The runways in the function argument is just a regular lua object, like any other.
If you hold a reference to it, it will never get removed from memory.


Corjan

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

Re: nav_get question

#15 Post by Shimokuta »

There seems do be something going wrong when, like i was trying , to nest one nav_get call from within a function is calling into another function
Then this seems to be disturebed.
But, i have changed my approach to use the nav_get funtion and read navdata from airac .
So, never mind this threat

Post Reply