Page 1 of 1

Restoring Default Doctrine Settings.

Posted: Tue Feb 23, 2021 3:46 pm
by jkgarner
When you create a unit, the default doctrine setting is for all settings to be inherited. This is reflected in the doctrine table returned by ScenEdit_GetDoctrine() with an empty table being returned from new units. This is fine. The documentation on doctrine lists the various values of the different aspects of doctrine, excluding the inherited value setting. When you twiddle the doctrine in the GUI, setting any one of the values to anything other than inherited, elements get added to the doctrine table returned by ScenEdit_GetDoctrine. Further, setting the values back to inherited removes those elements from the table in subsequent class. This is all nice and consistent.

Now the issue is when twiddling the doctrine through Lua. If I have a unit with several settings set to something other than inherited value (meaning there are several elements with values in the table) and then pass in a new table using ScenEdit_SetDoctrine with a value removed, that value is not altered or removed from the doctrine. Only those elements where I have a value different from what is there impacts teh unit's doctrine. Based on what I observed with ...GetDoctrine, I thought that non-existance in the input implies the value should be set to be inherited --the default value. However an argument against this methodology is that a person might accidentally include one that was previously set, producing an error. Further the current approach allows me to only push the values that need changing and everything else remains as it was (whatever it was) This is cool as well, but how do I set the value expressly to the inherited value? How do I get that element that I don';t care about out of the doctrine table, once I added it?

The accepted way in Lua to clear an element in a table is to expressly set the element to nil. I tried this way as will, and set the value that I wanted to return to be inherited (default) to nil in the input table, and submitted it to ScenEdit_SetDoctrine. This has no effect either. The function ignored the nil input as though it were invalid. The combination of the implemented behavior is that I can not find a way in Lua to reset a unit to it's default state after altering the Doctrine in any way. I can through the GUI, but not Lua.

Related to this are the following thoughts:
When altering doctrine in script:

1. What should be meant by ...SetDoctrine({unit selector}, {})
Make no change, or empty all values, setting everything to default?

2. What should be meant by ...SetDoctrine({unit selector}, {setting='1'}
Change only the value set,
or set everything but the named setting to inherited,
and set the value indicated?

In both cases, the later is more consistent with what ScenEdit_GetDoctrine returns.

Both are valid methodologies, however there must be a way to set the values back to inherited through Lua.

One way would be to hsve a clear function, that returns it to the default state (clear it all). I could call that as needed, and then expressly set everything else as I wanted. This works because the ...GetDoctrine funtion returns all non-defualt values, so I could grab that table before mucking with things and then return it when I was done.

Another way would be to allow nil values on a setting to clear the setting (typical for Lua)

Maybe both should be added.

What do the other Lua Ludites think?
er Lua Illuminaries think?





RE: Restoring Default Doctrine Settings.

Posted: Tue Feb 23, 2021 7:26 pm
by KnightHawk75
I agree there needs to be a way to reset them all to inherited.
re: #1
While I'm open to {} clearing\resetting to inherited, it's probably better it do nothing since various issues could happen where the table is empty by mistake or by prior error. I'd rather there just be a third optional parameter set to true to 'clear\reset' ie: SetDoctrine({unit selector}, {},true), or alternatively a setting of reset_all_inherited=yes or something that was looked for or processed first, which ever makes it easier on the implementation side.

re:#2
My thoughts are it should only change\touch\set what's explicitly specified in the call|submitted table.


"This is cool as well, but how do I set the value expressly to the inherited value?"
--
{use_refuel_unrep="inherit"} --format should be work for most of them, if you find one that doesn't it's probably a bug. Maybe I'm missing something in what you're saying.

"How do I get that element that I don';t care about out of the doctrine table, once I added it?"
--
So are you saying that if you set use_refuel_unrep to something then set it to "inherit", it's still coming back with GetDoctrine when not* using the 'actual=true' entry in the selector?










RE: Restoring Default Doctrine Settings.

Posted: Tue Feb 23, 2021 9:48 pm
by michaelm75au
This should work for individual doctrine options (which was what the function was originally designed for) to get it to fallback to the 'inherited' value.
<option>="inherit"

But I don't think I have one to reset all back to 'inherited'.

As I am working in this area at the moment, I will review what it does and how to do this.

RE: Restoring Default Doctrine Settings.

Posted: Tue Feb 23, 2021 11:56 pm
by jkgarner
Using {option]='inherit' did work, but it is clearly different than what standard Lua coding would suggest, which is <option>=nil removing the element.

I could live with <option>=nil,
I can make due with the current mechanism, now that I know it is there. (HINT: there is nothing in the documentation that says this works)

Thanks for the help.

RE: Restoring Default Doctrine Settings.

Posted: Wed Feb 24, 2021 2:40 am
by michaelm75au
ORIGINAL: jkgarner

Using {option]='inherit' did work, but it is clearly different than what standard Lua coding would suggest, which is <option>=nil removing the element.

I could live with <option>=nil,
I can make due with the current mechanism, now that I know it is there. (HINT: there is nothing in the documentation that says this works)

Thanks for the help.

It was set up that way as that is how the GetDoctrine() probably showed it and I wanted to make it easy to move data (as in using the output) from GetD() to SetD().

RE: Restoring Default Doctrine Settings.

Posted: Wed Feb 24, 2021 7:14 am
by jkgarner
So I threw together a quick function to clear the doctrine:

Code: Select all

function clearDoctrine(side_name, unit_name)
 	--test existence of input variables
 	if (side_name == nil or 
 		unit_name == nil) then 
 		return false
 	end
 
 	--test type of input variables
 	if (type(side_name) ~= 'string' or 
 		type(unit_name) ~= 'string') then 
 		return false
 	end
 
 	local unit = ScenEdit_GetUnit({side=side_name, name=unit_name})
 	if (unit == nil)
 		return false
 	end
 	
 	local doctrine = ScenEdit_GetDoctrine({side=side_name, name=unit_name})
 	if (doctrine ~= {})
 	    for k,v in pairs(doctrine) do
 			doctrine[k] = 'inherited'
 		end
 		ScenEdit_SetDoctrine({side=side_name, name=unit_name},doctrine)
 	end
 	return true
 end
Which works like a charm.
I can now take my output from GetDoctrine, then modify how I like, After I am done, call clear and use the output from GetDoctrien as my input of SetDoctrine.

Personally, I thing that SetDoctrine and GetDoctrine should work together as you describe, setting the whole value at a go, and assuming that non-existence impliues inherited. Then a separate ModifyDoctrine (or AlterDoctrine or ChangeDoctrine) would actually apply deltas only. (What Set currently seems to do)

That's my 2 cent's worth, take it or leave it.

Thanks for the help.

RE: Restoring Default Doctrine Settings.

Posted: Wed Feb 24, 2021 10:38 am
by jkgarner
cool.

RE: Restoring Default Doctrine Settings.

Posted: Fri Feb 26, 2021 11:05 pm
by michaelm75au
I am looking at the following change:
ScenEdit_SetDoctrine({name='DDG 96 Bainbridge [Arleigh Burke Flight IIA]', guid='GNRIJH-0HM6L55PUNQ6G'},{'inherit',avoid_contact = '2'})
You can include 'inherit' at the start of the doctrine table to force it to default to inherited values. Putting it at the start of the table means you can clear it out and then apply new settings in one go.
A blank table '{}' will also clear any non-inherited values, but the first option is probably more useful.

RE: Restoring Default Doctrine Settings.

Posted: Fri Feb 26, 2021 11:46 pm
by jkgarner
Using the empty table to clear is comparable to my clear function, only faster...
When implemented, that will replace my function, and its calls... that's easy enough. I actually like it, as it is very clear... I am clearing the doctrine.

As far as the first method: Since Lua tables do not guarantee order, requiring the 'inherit' to be at the front of the table, it is a non-Lua thought process, but it does allow one go.

As using the {} to clear, allows using the output of GetDoctine directly in a SetDoctrine call, I expect I'll favor that methodology.

Thanks.
[8D]