Restoring Default Doctrine Settings.
Posted: Tue Feb 23, 2021 3:46 pm
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?
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?