SOLVED: Get Location of a Selection of Reference Points

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
Bashkire
Posts: 78
Joined: Mon Feb 23, 2015 6:28 pm

SOLVED: Get Location of a Selection of Reference Points

Post by Bashkire »

SOLVED: Solution at the bottom

Hello all,

I hate to ask for help with something that seems to basic but LUA and I do not get along and despite looking through the LUA documentation and these threads I'm still drawing blanks.

I created a number of reference points (RPs) to plan out a course for a task group but now I realise that I saved the file under a different name and have since added to the older version - thereby making it the newer version (still with me?).

Unfortunately, this means that I no longer have those RPs that I placed to plan that course. However, I do still have the old file.

I need a piece of code that I can use to get the lat / longs of the RPs (named "AA" through to "QQ") from the outdated file and then recreate them in the updated version.

So far, I've tried:

Code: Select all

local Waypoints = ScenEdit_GetReferencePoints( { side="Royal Navy", area={ "AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH", "II", "JJ", "KK", "LL", "MM", "NN", "OO", "PP", "QQ"} } )
PRINT (Waypoints.lattitude)
PRINT (Waypoints.longitude)
but I get the return:

Code: Select all

ERROR:  [string "Console"]:2: attempt to call a nil value (global 'PRINT')
Using:

Code: Select all

local Waypoints = ScenEdit_GetReferencePoints( { side="Royal Navy", area={ "AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH", "II", "JJ", "KK", "LL", "MM", "NN", "OO", "PP", "QQ"} } )
PRINT (Waypoints.lattitude)
PRINT.(Waypoints.longitude)
returns:

Code: Select all

ERROR:  [string "Console"]:2: <name> expected near '('
I'm really sorry for asking something so basic, but this is really doing my head in now...










SOLUTION:
Disregard, all. It seems that I missed what was almost literally under my nose last night.

In order to acheive what I wanted, I found this piece of code written by KnightHawk75:
KnightHawk75 wrote:

Code: Select all

local rps = ScenEdit_GetReferencePoints({side='<Side_Name>', area={'RefPoint_1','RefPoint_2','etc'}});
if rps~= nil then
  for idx,rp in ipairs(rps) do
    print("Name: ".. rp.name.. "  Lat: " .. rp.latitude .." Lon: " .. rp.longitude);
  end
end
Thank you KnightHawk for being something of a genius in terms of LUA.
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: HELP: Get Location of a Selection of Reference Points

Post by KnightHawk75 »

NO worries. Waypoints here will be a table of refpoints, so you'll need to enumerate though the listing printing each, also Lua is very case sensitive so no caps with print.


Code: Select all

local waypoints = ScenEdit_GetReferencePoints( { side="Royal Navy", area={ "AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH", "II", "JJ", "KK", "LL", "MM", "NN", "OO", "PP", "QQ"} } )

for k,v in pairs(waypoints) do
 print(string.format('Name:  %s, Lat: %s, Lon: %s',v.name,v.latitude,v.longitude)); --k = key\index v is value|each rp object.
end
Should produce output like this (adjust as needed):
Name: RP-1, Lat: 42.173240645627, Lon: -100.184537330061
Name: RP-2, Lat: 39.5310398376205, Lon: -100.242280217711
Name: RP-3, Lat: 41.8847821771505, Lon: -96.8232968121394
Name: RP-4, Lat: 39.5368302555176, Lon: -97.1933663460857

opps sorry I replied before even seeing you solved it... from another one of my examples. lol funny I basically wrote the same example again though. haha
Bashkire
Posts: 78
Joined: Mon Feb 23, 2015 6:28 pm

Re: SOLVED: Get Location of a Selection of Reference Points

Post by Bashkire »

Absolutely stellar, mate. Cheers for all the help you've given to me and everyone else on here!
Post Reply

Return to “Lua Legion”