sourcemod
sourcemod copied to clipboard
Add KeyValues.Merge
AI in Discord brought up that Import/CopySubkeys doesn't do what you want if you want to merge together KVs. Although it does copy the foreign data in, it also replaces the existing data when it does so. To get around this, his workaround was to manually iterate, create, and import:
if (!hKVSource.GotoFirstSubKey(false)) {
return;
}
char sSectionName[256];
do {
hKVSource.GetSectionName(sSectionName, sizeof(sSectionName));
hKVDestination.JumpToKey(sSectionName, true);
hKVDestination.Import(hKVSource);
hKVDestination.GoBack();
} while (hKVSource.GotoNextKey(false));
With this PR, you should be able to just do hKVDestination.Merge(hKVSource).
I think the docs should mention that this preserves the old value if the key already exists. That's what I understood from your PR description.