Yes, but that was my issue
Why is the table not persistent outside the nav_get function?
nav_get question
-
- Posts: 5339
- Joined: Thu Jul 27, 2017 12:22 am
Re: nav_get question
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 = {"","","","","","","","","",""}
Re: nav_get question
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 .
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()
Re: nav_get question
Hi,
Maybe I'm missing something, but you should be able to store the runways in a global variable.
Something like this:
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
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)
If you hold a reference to it, it will never get removed from memory.
Corjan
Re: nav_get question
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
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