Unit:inArea() returns No when using ScenEdit_AddReferencePoint() generated reference points
Posted: Sat Nov 13, 2021 9:31 am
I apologize for the multiple posts. I'm receiving an error of "You are not allowed to post links, emails or phone numbers for 7 days from the date of your tenth post." for posts with content such as the Command build and version numbers. I've determined the forum dislikes long numbers (lat and lon to 13 decimal places)
How do I use programmatically generated reference points with the Unit:inArea() function?
BLUF:
Command Version One dot Zero four, Build One-Thousand One-Hundred and forty-seven dot thirty-four
Lua_AddReferencepointError.scen
Test_InArea.lua.txt - Script to run in Lua Script Console
The Unit:inArea({'RP-6380','RP-6381','RP-6382','RP-6383'}) works as expected with manually created reference points, but does not produce a proper result with ScenEdit_AddReferencePoint() generated reference points. I'd thought the issue was a name format and added the ability to use mimicry (RP-...). that doesn't fix it either.
I attached the .scen file with the manual RPs and lua to run in the Lua script console. You can also create a new scenario, define the area manually area as N49, 37', 40"/W2,32',20" x N49,24',30/W2,18',40" and run the following test function.
Code to reproduce is attached in the Test_InArea.lua.txt.
This isn't a blocker, but it prevents a unit test for a function. It will be when I use actions to dynamically deploy randomized reference points.
==================================================================
==================================================================
function TestInArea()
-- Define area as N49, 37', 40"/W2,32',20" x N49,24',30/W2,18',40"
--Enter the RP Names below
local mrp1 = 'RP-6380'
local mrp2 = 'RP-6381'
local mrp3 = 'RP-6382'
local mrp4 = 'RP-6383'
local nameRp1 = 'PortsInAreaA'
local nameRp2 = 'PortsInAreaB'
local nameRp3 = 'PortsInAreaC'
local nameRp4 = 'PortsInAreaD'
mimicmanualnames = false
if mimicmanualnames then
nameRp1 = 'RP-9100'
nameRp2 = 'RP-9101'
nameRp3 = 'RP-9102'
nameRp4 = 'RP-9103'
end
--setup
testside = VP_GetSides ()[1].name
local port = { name = 'Saint Sampson', shore = { latitude = 49.48, longitude = -2.45 }, harbor = { latitude = 49.51, longitude = -2.42 }, country = 'Guernsey' }
local retval,shipT = pcall(ScenEdit_AddUnit,{type ='Ship', unitname =port.name .. " Buoy", dbid=347, side =VP_GetSides ()[1].name, Lat=port.harbor.latitude,Lon=port.harbor.longitude}) ;
local testship
if not retval or shipT ~= nil then
testship = ScenEdit_GetUnit({name=shipT.name , guid=shipT.guid});
end
size = 1
local rp1=ScenEdit_AddReferencePoint( {side=testside, name=nameRp1, lat=testship.latitude + (size/10), lon=testship.longitude + (size/10), highlighted=true})
local rp2=ScenEdit_AddReferencePoint( {side=testside, name=nameRp2, lat=testship.latitude + (size/10), lon=testship.longitude - (size/10), highlighted=true})
local rp3=ScenEdit_AddReferencePoint( {side=testside, name=nameRp3, lat=testship.latitude - (size/10), lon=testship.longitude + (size/10), highlighted=true})
local rp4=ScenEdit_AddReferencePoint( {side=testside, name=nameRp4, lat=testship.latitude - (size/10), lon=testship.longitude - (size/10), highlighted=true})
-- test
if testship ~= nil then
t = testship:inArea({'RP-6380','RP-6381','RP-6382','RP-6383'})
t = testship:inArea({mrp1,mrp2,mrp3,mrp4})
print("Manual RPs tested testship:inArea({'" .. mrp1 .. "','" .. mrp2 .. "','" .. mrp3 .. "','" .. mrp4 .. "'}) match:")
print(t)
t = testship:inArea({nameRp1,nameRp1,nameRp1,nameRp1})
print("Lua based RPs ceated using ScenEdit_AddReferencePoint tested testship:inArea({'" .. nameRp1 .. "','" .. nameRp2 .. "','" .. nameRp3 .. "','" .. nameRp4 .. "'}) match:")
print(t)
t = testship:inArea({rp1.name,rp2.name,rp3.name,rp4.name})
print("Lua based RPs ceated using ScenEdit_AddReferencePoint tested testship:inArea({rp1.name,rp2.name,rp3.name,rp4.name}) match:")
print(t)
t = testship:inArea({rp1.guid,rp2.guid,rp3.guid,rp4.guid})
print("Lua based RPs ceated using ScenEdit_AddReferencePoint tested testship:inArea({rp1.guid,rp2.guid,rp3.guid,rp4.guid}) match:")
print(t)
end
-- cleanup
strnum = ScenEdit_InputBox ('pause before cleanup')
if testship ~= nil and testship:delete() then end
ScenEdit_DeleteReferencePoint ({side=testside, guid=rp1.guid})
ScenEdit_DeleteReferencePoint ({side=testside, guid=rp2.guid})
ScenEdit_DeleteReferencePoint ({side=testside, guid=rp3.guid})
ScenEdit_DeleteReferencePoint ({side=testside, guid=rp4.guid})
end
TestInArea()
How do I use programmatically generated reference points with the Unit:inArea() function?
BLUF:
Command Version One dot Zero four, Build One-Thousand One-Hundred and forty-seven dot thirty-four
Lua_AddReferencepointError.scen
Test_InArea.lua.txt - Script to run in Lua Script Console
The Unit:inArea({'RP-6380','RP-6381','RP-6382','RP-6383'}) works as expected with manually created reference points, but does not produce a proper result with ScenEdit_AddReferencePoint() generated reference points. I'd thought the issue was a name format and added the ability to use mimicry (RP-...). that doesn't fix it either.
I attached the .scen file with the manual RPs and lua to run in the Lua script console. You can also create a new scenario, define the area manually area as N49, 37', 40"/W2,32',20" x N49,24',30/W2,18',40" and run the following test function.
Code to reproduce is attached in the Test_InArea.lua.txt.
This isn't a blocker, but it prevents a unit test for a function. It will be when I use actions to dynamically deploy randomized reference points.
==================================================================
==================================================================
function TestInArea()
-- Define area as N49, 37', 40"/W2,32',20" x N49,24',30/W2,18',40"
--Enter the RP Names below
local mrp1 = 'RP-6380'
local mrp2 = 'RP-6381'
local mrp3 = 'RP-6382'
local mrp4 = 'RP-6383'
local nameRp1 = 'PortsInAreaA'
local nameRp2 = 'PortsInAreaB'
local nameRp3 = 'PortsInAreaC'
local nameRp4 = 'PortsInAreaD'
mimicmanualnames = false
if mimicmanualnames then
nameRp1 = 'RP-9100'
nameRp2 = 'RP-9101'
nameRp3 = 'RP-9102'
nameRp4 = 'RP-9103'
end
--setup
testside = VP_GetSides ()[1].name
local port = { name = 'Saint Sampson', shore = { latitude = 49.48, longitude = -2.45 }, harbor = { latitude = 49.51, longitude = -2.42 }, country = 'Guernsey' }
local retval,shipT = pcall(ScenEdit_AddUnit,{type ='Ship', unitname =port.name .. " Buoy", dbid=347, side =VP_GetSides ()[1].name, Lat=port.harbor.latitude,Lon=port.harbor.longitude}) ;
local testship
if not retval or shipT ~= nil then
testship = ScenEdit_GetUnit({name=shipT.name , guid=shipT.guid});
end
size = 1
local rp1=ScenEdit_AddReferencePoint( {side=testside, name=nameRp1, lat=testship.latitude + (size/10), lon=testship.longitude + (size/10), highlighted=true})
local rp2=ScenEdit_AddReferencePoint( {side=testside, name=nameRp2, lat=testship.latitude + (size/10), lon=testship.longitude - (size/10), highlighted=true})
local rp3=ScenEdit_AddReferencePoint( {side=testside, name=nameRp3, lat=testship.latitude - (size/10), lon=testship.longitude + (size/10), highlighted=true})
local rp4=ScenEdit_AddReferencePoint( {side=testside, name=nameRp4, lat=testship.latitude - (size/10), lon=testship.longitude - (size/10), highlighted=true})
-- test
if testship ~= nil then
t = testship:inArea({'RP-6380','RP-6381','RP-6382','RP-6383'})
t = testship:inArea({mrp1,mrp2,mrp3,mrp4})
print("Manual RPs tested testship:inArea({'" .. mrp1 .. "','" .. mrp2 .. "','" .. mrp3 .. "','" .. mrp4 .. "'}) match:")
print(t)
t = testship:inArea({nameRp1,nameRp1,nameRp1,nameRp1})
print("Lua based RPs ceated using ScenEdit_AddReferencePoint tested testship:inArea({'" .. nameRp1 .. "','" .. nameRp2 .. "','" .. nameRp3 .. "','" .. nameRp4 .. "'}) match:")
print(t)
t = testship:inArea({rp1.name,rp2.name,rp3.name,rp4.name})
print("Lua based RPs ceated using ScenEdit_AddReferencePoint tested testship:inArea({rp1.name,rp2.name,rp3.name,rp4.name}) match:")
print(t)
t = testship:inArea({rp1.guid,rp2.guid,rp3.guid,rp4.guid})
print("Lua based RPs ceated using ScenEdit_AddReferencePoint tested testship:inArea({rp1.guid,rp2.guid,rp3.guid,rp4.guid}) match:")
print(t)
end
-- cleanup
strnum = ScenEdit_InputBox ('pause before cleanup')
if testship ~= nil and testship:delete() then end
ScenEdit_DeleteReferencePoint ({side=testside, guid=rp1.guid})
ScenEdit_DeleteReferencePoint ({side=testside, guid=rp2.guid})
ScenEdit_DeleteReferencePoint ({side=testside, guid=rp3.guid})
ScenEdit_DeleteReferencePoint ({side=testside, guid=rp4.guid})
end
TestInArea()