SE_GetReferencePoints()

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
User avatar
vettim89
Posts: 3668
Joined: Fri Jul 13, 2007 11:38 pm
Location: Toledo, Ohio

SE_GetReferencePoints()

Post by vettim89 »

First of all are there two Lua commands: SE_GetReferencePoints() and SE_GetReferencePoint()? or is the same command used for getting one or multiple RPs?

I have created a bunch or missions that have a 'unit remains in area trigger'. I want the player to be able to see the trigger zone so they know where to send the units. It occurred to me that a crafty player could simply move the RPs and make life easier. No problem (I thought) I will just use Lua to clone the RPs from the player side to a non-player side and then use the new RPs for the trigger while retaining the visible RPs on player side so it is obvious where the units need to go.

When I use SE_GetReferencePoints() I get an empty value. For example:

>> local r
r=ScenEdit_GetReferencePoints({side='USSR', name='Banak 1'})
print(r.latitude)



nil<<


is what I get in the console if I run the above code.

What am I missing?
"We have met the enemy and they are ours" - Commodore O.H. Perry
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: SE_GetReferencePoints()

Post by KnightHawk75 »

GetReferencePoint() is always for just 1 and returns a RP.
GetReferencePoints() is for 1 or more using a comma delimited list of names vs a singular name value and returns a table of RPs.

So in your code it's two things. First is that you asked for multiple rp's when using GetReferencePoints(), thus you get back a table of reference points (or an empty table) and need to access the return value as such. Also your parameters are missing the area= list parameter that is used by the S() variant for the list of rp names to go get.

Code: Select all

--sample 1 get points with singular point in the list to grab, basic for used to navigate each rp (fastest).
local rps = ScenEdit_GetReferencePoints({side='USSR', area={'Banak 1'}});
if (rps~= nil) and #rps > 0 then
  for i = 1,#rps do
    print("Name: ".. rps[i].name.. "  Lat: " .. rps[i].latitude .." Lon: " .. rps[i].longitude);
  end
end

--sample 2 use multiple points in the list to grab, for each used to navigate each rp. (easier to follow for some)
local rps = ScenEdit_GetReferencePoints({side='USSR', area={'Banak 1','Banak 2'}});
if rps~= nil then
  for idx,rp in ipairs(rps) do
    print("Name: ".. rp.name.. "  Lat: " .. rp.latitude .." Lon: " .. rp.longitude);
  end
end
output:
Name: Banak 1 Lat: 41.6916769558626 Lon: -100.235818284247
Name: Banak 1 Lat: 41.6916769558626 Lon: -100.235818284247
Name: Banak 2 Lat: 40.4295625867722 Lon: -93.1240337091142
bkmeneguello
Posts: 3
Joined: Fri Dec 02, 2022 1:53 pm

Re: SE_GetReferencePoints()

Post by bkmeneguello »

Is it normal for the latitude and longitude values to be a string with the decimal places separated by a comma?
In my code,

Code: Select all

print(rp.latitude.. " type ".. type(rp.latitude))
the output is

Code: Select all

2,38968000241466 type string
User avatar
michaelm75au
Posts: 12457
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

Re: SE_GetReferencePoints()

Post by michaelm75au »

It is showing the decimal point character as per your Windows locale setting.
With US locale, I am showing a 'dot'.
Michael
bkmeneguello
Posts: 3
Joined: Fri Dec 02, 2022 1:53 pm

Re: SE_GetReferencePoints()

Post by bkmeneguello »

But shouldn't it be a "number" instead of a string?
User avatar
michaelm75au
Posts: 12457
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

Re: SE_GetReferencePoints()

Post by michaelm75au »

The output is defined as a string. That is how it was originally set up as.

If you want to treat it as a number, use "tonumber()" as in tonumber(rp.latitude)
Michael
bkmeneguello
Posts: 3
Joined: Fri Dec 02, 2022 1:53 pm

Re: SE_GetReferencePoints()

Post by bkmeneguello »

So, that's an error in docs, that say it should return a table of ReferencePoint whose latitude and longitude are numbers.
User avatar
michaelm75au
Posts: 12457
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

Re: SE_GetReferencePoints()

Post by michaelm75au »

You are correct.
The RP wrapper uses a number for longitude/latitude. But the 'GetPoints' doesn't return a list of wrappers, but a dump of each RP in the table.
I must have copied the 'GetPoint' to the 'GetPoints' in the Docs without realizing it.

Will correct.
Michael
Post Reply

Return to “Lua Legion”