plugin:DestroySetting()

As a plugin developer, it is currently too hard to erase or forget settings saved through plugin:SetSetting(). Attempting to simply over-write the existing setting with nil will throw an error and not change the data.

Presently, the only option is it over-write it with some identifier to signal that it shouldn’t be used (for example, my plugin uses the string “STT_DELETED”) but this requires additional code in other areas to not only compare it to nil, but to the identifier as well. Also, it makes it a pain to edit the JSON file, because it’s full of unused settings.

To fix this issue, I’d suggest adding plugin:DestroySetting(key), a function that would, as the name suggests, destroy the setting, removing the key and its value from the JSON file.

My personal use case is for adding a “clear all preferences” feature to my time tracker plugin. When bad or malformed data gets saved, it’s possible to remove it by editing the JSON file, but that can be tricky, and a pretty bad user experience-having a way to do it through code would be much better.

Edit: Implemented as of version 406! Dreams DO come true!

4 Likes

I’m curious, what’s the use-case for this? Why is it bad to leave settings that you aren’t using? And how often do you set settings knowing that they will become redundant?

You’ll have to add use cases, right now this is just a proposed solution and that’s not going to convince anyone to prioritize or implement this. Why do you feel you have to delete the value of a setting? Do you need this for something functional?

Regarding the proposed solution, a better solution IMO would be to just allow passing nil to SetSetting.

3 Likes