Page 1 of 1

SE_GetReferencePoints()

Posted: Sun May 01, 2022 7:35 pm
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?

Re: SE_GetReferencePoints()

Posted: Mon May 02, 2022 1:17 pm
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

Re: SE_GetReferencePoints()

Posted: Fri Dec 02, 2022 1:56 pm
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

Re: SE_GetReferencePoints()

Posted: Fri Dec 02, 2022 11:08 pm
by michaelm75au
It is showing the decimal point character as per your Windows locale setting.
With US locale, I am showing a 'dot'.

Re: SE_GetReferencePoints()

Posted: Sat Dec 03, 2022 11:37 am
by bkmeneguello
But shouldn't it be a "number" instead of a string?

Re: SE_GetReferencePoints()

Posted: Sat Dec 03, 2022 12:04 pm
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)

Re: SE_GetReferencePoints()

Posted: Sat Dec 03, 2022 5:15 pm
by bkmeneguello
So, that's an error in docs, that say it should return a table of ReferencePoint whose latitude and longitude are numbers.

Re: SE_GetReferencePoints()

Posted: Sat Dec 03, 2022 9:48 pm
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.