Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

Unit:inArea() returns No when using ScenEdit_AddReferencePoint() generated reference points

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Tech Support >> Unit:inArea() returns No when using ScenEdit_AddReferencePoint() generated reference points Page: [1]
Login
Message << Older Topic   Newer Topic >>
Unit:inArea() returns No when using ScenEdit_AddReferen... - 11/13/2021 11:31:51 AM   
rneum

 

Posts: 12
Joined: 11/12/2021
Status: offline
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()

Attachment (1)

< Message edited by rneum -- 11/13/2021 11:55:48 AM >
Post #: 1
RE: Unit:inArea() returns No when using ScenEdit_AddRef... - 11/14/2021 7:06:15 AM   
KnightHawk75

 

Posts: 1450
Joined: 11/15/2018
Status: offline
See my attached testbed sample for a functional example.
You can either look at the special actions or to test under 'event' conditions enable the regularly timed event.
Both execute the following for the auto-generation test (that also include a test of manually placed tanker in the scene).
It creates the rp's and then uses them in a unit:inArea() test, that should be true based on it's generate location.
local function TestAutoRPS() 
  local autolats = {26.077119, 26.092939, 23.935986, 23.917725}
  local autolons = {-95.459756, -91.126452, -91.078016, -95.414230}
  local autonamebase = "Auto-";
  local autosidename = "Green";
  local autorps = {}
  local u = SE_GetUnit({side="Green",name="Tanker VLCC #1"})
  local retvalu2,u2 = pcall(ScenEdit_AddUnit,{side=autosidename,type="Ship",dbid=259,name="AutoGen Tanker VLCC",latitude=25.0849,longitude=-93.0443,heading=0,speed=0})
  print('adding auto ref points.');
  for i = 1,4 do
    autorps[i] = ScenEdit_AddReferencePoint({side=autosidename, name=autonamebase .. tostring(i), latitude=autolats[i], longitude=autolons[i]})
    if autorps[i] ~= nil then print('refpoint '.. tostring(autorps.name) .. ' added.') end
  end
  print("-- Sanity checking. --")
  print("verifying autorps returns");
  for k,v in ipairs(autorps) do
    print(v.name .. ":  lat: " ..v.latitude .. " lon: " .. v.longitude )
  end
  print("verifying autorps with side lookup and getrefpoint calls")
  local s = VP_GetSide({side="Green"})
  for k,v in ipairs(s.rps) do
    if string.find(v.name,'Auto-',1,true) ~= nil then --filter for only Auto-xx rps
      print("getting refference point for " .. v.name)
      local rp = ScenEdit_GetReferencePoint({side="Green",guid=v.guid})
      print("rp obtained - " ..rp.name .. ":  lat: " ..rp.latitude .. " lon: " .. rp.longitude )
      rp = nil;
    end
  end
  print("-- End sanity checking. --");
  if #autorps == 4 then --Do we have list and right number of autogen rps?
    local retval = u:inArea({'Auto-1','Auto-2','Auto-3','Auto-4'})
    print('Manual tanker is in the Auto-X area? ' .. tostring(retval));
    ScenEdit_MsgBox("Manual tanker is in the Auto-X rp Area? : " .. tostring(retval),1)
  end
  if (retvalu2 ==true) and u2 ~=nil then --was unit creation successful?
    local retval = u2:inArea({'Auto-1','Auto-2','Auto-3','Auto-4'})
    print('Auto generated tanker is in the Auto-X area? ' .. tostring(retval));
    ScenEdit_MsgBox("Auto generated tanker is in the Auto-X Area? : " .. tostring(retval),1)
  end
  --cleanup
  if u2 ~=nil then --if unit exists remove it.
    print("removing Auto generated unit.");
    u2:delete();
  end
  print("removing Auto-X ref points.")
  for i=1,#autorps do
    if autorps[i] ~= nil then --skip if nil.
      local strsuccess = "Removed RP " .. tostring(autorps[i].name) .. "  by guid:".. tostring(autorps[i].guid);
      local retval1 = ScenEdit_DeleteReferencePoint({side=autosidename,guid=autorps[i].guid});
      if retval1 then print(strsuccess); else print('failed to remove'); end
    end
  end
end
TestAutoRPS();

Can also just plop the above into the console after loading the scene.
I'll have to dig into yours to see where things go wrong, probably something simple but not obvious at first glance.

Attachment (1)

(in reply to rneum)
Post #: 2
RE: Unit:inArea() returns No when using ScenEdit_AddRef... - 11/14/2021 8:18:03 AM   
KnightHawk75

 

Posts: 1450
Joined: 11/15/2018
Status: offline
rneum,

Two problems in your original code:
first (primarily):
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}) 

These two need to be reversed, the location calculated for #2 needed to be first, and the first one needs to be second, if you want a 4pt poly box shape. (this would fail normal geometric validation without it... on the map before cleanup you can see A is to the right of B). As it was unit actually was not really inside given the order of submission.

Second:
    t = testship:inArea({nameRp1,[b]nameRp1,nameRp1,nameRp1[/b]}) <--you forgot to change the last 3 varnames.


Attached is your .txt file updated (working) with my changes (some vars weren't 'local' and I tweaked a few others, but the crux was what was already mentioned.)


Attachment (1)

< Message edited by KnightHawk75 -- 11/14/2021 8:21:23 AM >

(in reply to rneum)
Post #: 3
RE: Unit:inArea() returns No when using ScenEdit_AddRef... - 12/10/2021 10:29:50 AM   
rneum

 

Posts: 12
Joined: 11/12/2021
Status: offline
Thank you, the order of reference points. SMH

(in reply to KnightHawk75)
Post #: 4
RE: Unit:inArea() returns No when using ScenEdit_AddRef... - 12/21/2021 8:14:01 AM   
jannas34

 

Posts: 76
Joined: 1/9/2020
Status: offline
lololol this is not getting fixed

(in reply to rneum)
Post #: 5
RE: Unit:inArea() returns No when using ScenEdit_AddRef... - 12/22/2021 6:09:10 AM   
KnightHawk75

 

Posts: 1450
Joined: 11/15/2018
Status: offline

quote:

ORIGINAL: jannas34

lololol this is not getting fixed

Jannas34 - Did you read the thread? There was nothing to fix, it was just user error.

(in reply to jannas34)
Post #: 6
RE: Unit:inArea() returns No when using ScenEdit_AddRef... - 12/22/2021 10:44:18 AM   
thewood1

 

Posts: 6529
Joined: 11/27/2005
Status: offline
What do you think the answer to that is? Does no one realize this guy posted in over 20 threads with similar messages. Why are wasting the effort in responding?

_____________________________

You are like puss filled boil on nice of ass of bikini model. You are nasty to everybody but then try to sweeten things up with a nice post somewhere else. That's nice but you're still a boil on a beautiful thing! - BDukes

(in reply to KnightHawk75)
Post #: 7
RE: Unit:inArea() returns No when using ScenEdit_AddRef... - 12/22/2021 4:28:49 PM   
KnightHawk75

 

Posts: 1450
Joined: 11/15/2018
Status: offline

quote:

ORIGINAL: thewood1

What do you think the answer to that is? Does no one realize this guy posted in over 20 threads with similar messages. Why are wasting the effort in responding?

Answer to what is?
Yes I realized, _after_ this and a few other posts

(in reply to thewood1)
Post #: 8
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Tech Support >> Unit:inArea() returns No when using ScenEdit_AddReferencePoint() generated reference points Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

1.594