jkgarner -> Unit Name Uniqueness (5/14/2021 7:23:27 AM)
|
HI, I thought I would test what happens if multiple units were created using the same name (and side!) I believe that this should not happen, as having multiple units in a scenario of the same name and side would be confusing to the player, and it is incumbent upon the developer to keep his/her data straight enough to prevent this, however, I thought I would investigate the possibility. The following is the test code:
ScenEdit_AddSide({name='USA'})
print('adding furst unit')
local u1 = ScenEdit_AddUnit({side='USA', type='Facility', guid='test unit 1', dbid=2784,
name='Generic Unit Name', latitude=19.004100276608, longitude=110.24596193077, })
local g1 = u1.guid
print('guid unit1 = '..g1)
print('')
print('adding second unit')
local u2 = ScenEdit_AddUnit({side='USA', type='Facility', guid='test unit 2', dbid=2784,
name='Generic Unit Name', latitude=19.002716269866, longitude=110.16686023683, })
local g2 = u2.guid
print('guid unit2 = '..g2)
print('')
print('getting unit with side and name:')
local res1 = ScenEdit_GetUnit({side='USA', name='Generic Unit Name'})
print(res1)
print('')
print('getting unit with guid:')
local res2 = ScenEdit_GetUnit({guid=g1})
print(res2)
print('')
print('getting unit with guid:')
local res3 = ScenEdit_GetUnit({guid=g2})
print(res3)
When executed, the code created two distinct units, and both were accessible from lua, ONLY if using the guid in the unit selector of ScenEdit_GetUnit. The first unit ONLY was returned when using side and name in the unit selector of ScenEdit_GetUnit. I would note that I intentionally used custom guid's and intentionally set them distinct from one another. If you allow the system to set the guid values, then it will generate unique values for you and behave in essentially the same fashion. If, however, you choose to use custom guid's, and attempt to create a second unit with the same guid as has been previously used, it will fail. What does this mean? If you allow the system to generate guids for you, and you use them to access your units, then you can be sloppy about your unit name data. The result will be a confused user, but the system will likely work. If you choose to use custom guid values, and use them to access the units, then you can be sloppy about the unit names but you MUST track you custom guid usage and guarantee they are unique. Depending upon how your data is configured, this may already be the case (if you use a primary key of this data as the guid) If you use some other data, you have just created a task of equal complexity as tracking unit name uniqueness directly. If you wish to use name and side, and ignore guid values entirely, then you must ensure that side and unit name pair are unique across all the units you create. In my mind, this leads to the most clarity for the user. Now you know.[:)]
|
|
|
|