Page 1 of 1
[Logged] AddUnit function changes input causing problem
Posted: Wed Jul 22, 2020 3:29 am
by DracheTek
When input a barebone unit selector-name, type, side, position, dbid- in the function ScenEdit_AddUnit, the function autonomously fill the unit selector with information from spawned unit, especially guid, which will prevent me from spawning another unit with the original unit selector. This is annoying when I am doing a loop spawning multiple units using one set of data. Plus, it seems inconsistence with AddReferencePoint, which does not alter selector.
Currently my workaround is to do a hard copy of unit selector, and a new workaround is to set new properties to nil, but it will longer my code about twice.
RE: AddUnit function changes input causing problem
Posted: Wed Jul 22, 2020 3:47 am
by Rory Noonan
Can you post some example code and a scenario for us to look at? It's not immediately clear what the issue is
RE: AddUnit function changes input causing problem
Posted: Wed Jul 22, 2020 9:47 pm
by DracheTek
EXAMPLE:
Code: Select all
target = {name = 'TEST', latitude = *SOME LAT*, longitude = *SOME LON*, type = 'Ship', dbid = *Some Random DBID*, side = 'RED'}
ScenEdit_AddUnit(target)
print(target)
--OUTPUT: { speed = 0, side = 'RED', throttle = FullStop, desiredheading = 0, heading = 0, guid = '0IYVAT-0HM1EJSER3RM4', dbid = 1024, name = 'TEST', unitname = 'TEST', type = 'Ship', longitude = 122, latitude = 26 }
--Note that it autonomously filled in a guid to the input unit selector, and I cannot use this input to generate units again because of the conflicting GUID.
RE: AddUnit function changes input causing problem
Posted: Wed Jul 22, 2020 10:30 pm
by Rory Noonan
Thanks, I see your issue now.
A simple solution is:
local target = {name = 'TEST', latitude = *SOME LAT*, longitude = *SOME LON*, type = 'Ship', dbid = *Some Random DBID*, side = 'RED'}
local thisUnit = ScenEdit_AddUnit(name=target.name, type=target.type, dbid=target.dbid, side=target.side, latitude=target.latitude, longitude=target.longitude)
print(thisUnit)
We'll see if there's any improvements that can be made.
0014038
RE: AddUnit function changes input causing problem
Posted: Thu Jul 23, 2020 1:06 am
by KnightHawk75
Yup, that or just target.guid = nil before the next addunit call should work around it.