[Logged] AddUnit function changes input causing problem

Post bug reports and ask for game support here.

Moderator: MOD_Command

Post Reply
DracheTek
Posts: 46
Joined: Sun Jul 05, 2020 11:55 am

[Logged] AddUnit function changes input causing problem

Post 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.
Rory Noonan
Posts: 2419
Joined: Thu Dec 18, 2014 1:53 am
Location: Brooklyn, NY

RE: AddUnit function changes input causing problem

Post 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
Image
DracheTek
Posts: 46
Joined: Sun Jul 05, 2020 11:55 am

RE: AddUnit function changes input causing problem

Post 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.
 
 
 
 
Rory Noonan
Posts: 2419
Joined: Thu Dec 18, 2014 1:53 am
Location: Brooklyn, NY

RE: AddUnit function changes input causing problem

Post 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
Image
KnightHawk75
Posts: 1556
Joined: Thu Nov 15, 2018 7:24 pm

RE: AddUnit function changes input causing problem

Post by KnightHawk75 »

Yup, that or just target.guid = nil before the next addunit call should work around it.
Post Reply

Return to “Tech Support”