Question Way to Access Base and City Markers in MFD Script

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,356
Reaction score
3,291
Points
138
Location
Massachusetts
I am looking for a way to get base and city lat/long data into an script MFD waypoint autopilot like what is available to the stock Map MFD function. I am not seeing a ready way to access this information through the API. I am aware the marker files are available in Orbiter 2016/Config/Earth/Marker, but really wanted to avoid trying to do file I/O through Lua. Does anybody know if this is possible through an API script function?
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,606
Reaction score
2,328
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
I am looking for a way to get base and city lat/long data into an script MFD waypoint autopilot like what is available to the stock Map MFD function. I am not seeing a ready way to access this information through the API. I am aware the marker files are available in Orbiter 2016/Config/Earth/Marker, but really wanted to avoid trying to do file I/O through Lua. Does anybody know if this is possible through an API script function?

Sadly not. Same for the base layout or runway data. I already think about making a proposal to extend the Orbiter SDK in the open source project with such helpers, because it could solve quite many add-on problems.
 

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,356
Reaction score
3,291
Points
138
Location
Massachusetts
Sadly not. Same for the base layout or runway data.
An ILS autopilot isn't going to be easy then, either. Blah. :(
I already think about making a proposal to extend the Orbiter SDK in the open source project with such helpers, because it could solve quite many add-on problems.
Good. 👍
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,606
Reaction score
2,328
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
Its at least better now. Before 2016, we already had a campaign "Free the NAVHANDLE" to gain API functions for working with the navigation beacons.
 

Thunder Chicken

Fine Threads since 2008
Donator
Joined
Mar 22, 2008
Messages
4,356
Reaction score
3,291
Points
138
Location
Massachusetts
OK, so I have a function that reads the Cities.mkr marker file and converts it to a table of waypoint tables (each contains the lat/long and city name):


Code:
function marker2waypoint()

    city_waypoints = {}
    n_cities = 0

    file = io.open("/home/ThunderChicken/Documents/Orbiter 2016/Config/Earth/Marker/Cities.mkr", "r")
 
    lines = file:lines()

    for line in lines do
    
        if string.find(line, ": ") then

            n_cities = n_cities + 1
            temp_table = {}
            city_waypoint = {}
            i = 0
    
            for str in string.gmatch(line, "[^%s]+") do
                i = i + 1
                table.insert(temp_table, i, str)
            end

            city_waypoint = {lat=math.rad(tonumber(temp_table[1])), lng=math.rad(tonumber(temp_table[2])), city=table.concat(temp_table,' ', 4,i)}

            table.insert(city_waypoints, n_cities, city_waypoint)

        end

    end

    io.close(file)

    return city_waypoints

end

This code works correctly, and the hope is that I can cycle through the cities using the table index for each waypoint table.

The above code should only have to run once as it basically is just taking the data in the existing .mkr file and converting it into Lua tables. But it only seems to work in either the prestep or poststep callbacks, which does work but it's obviously rather wasteful as it repeatedly opens, reads, and closes files and continuously overwrites the tables every time step. I've tried various ways of getting to run only once using code like this in the prestep callback:

Code:
if simt == 0 then
city_waypoints = marker2waypoint()
end

but it does not seem to work. I'm rather baffled in that I can't seem to run it once and then pass it into the pre or poststep callbacks for some reason.

EDIT: I made a flag that toggles from false to true when the markers are converted to waypoint tables so that code only runs once. It still has to check the flag every time step, but that is much cheaper than running the conversion repeatedly. My laptop isn't at risk of bursting into flames anymore.
 
Last edited:
Top