Retaining config values (.ini settings) when upgrading mods?

Discussions about Coding and Scripting
Post Reply
User avatar
Dizzy
Experienced
Posts: 109
Joined: Tue May 21, 2013 3:57 pm
Personal rank: Oaf
Contact:

Retaining config values (.ini settings) when upgrading mods?

Post by Dizzy »

Is there an established method for retaining a mod's settings inside .ini files (both client- and server-side) when you are upgrading or renaming your mods?

For example, let's say you are running a mod called MyCoolModv1, and you want to upgrade to MyCoolModv2.

Before the upgrade, your .ini files might look like this:
• Server-side settings: stored on servers as MyCoolMod_ServerSide.ini under a section called [MyCoolModv1.CoolStuff].
• Client-side settings: stored on clients as MyCoolMod_ClientSide.ini under a section called [MyCoolModv1.CoolStuff].

After you upgrade, however, the mod now looks for settings in the .inis, but under [MyCoolModv2.CoolStuff]. Since those settings don't exist, it uses the default values. Server-side, this isn't a problem because the admin can just copy/paste the settings under the new heading. But clients don't have the knowledge to do this.

I'm aware of one potential solution where you can use a second separate mod just for storing settings, whose name should not change when you update the main mod. For example, the mod "BTPlusPlusv009" uses a separate package called "BTPPUser" to store settings under "[BTPPUser.ClientData]" -- and this works, up until you want to extend the number of settings available in the mod, or change the names of some of those settings, in which case you find yourself needing to update (and therefore rename) BTPPUser to BTPPUser_v2 and face the same problem all over again.

So how have others solved this problem?

Is there a design pattern or a method where you can actually specify arbitrary .ini, package and class names to store and retrieve settings data?

I'm imagining some code like

Code: Select all

MaxPlayers = SettingsManager.GetSetting("MyCoolMod.ini", "MyCoolMod.CoolStuff", "MaxPlayers");
Join the BunnyTrack.net Discord chat server: https://www.bunnytrack.net/discord
sn260591
Average
Posts: 75
Joined: Sat Jun 01, 2013 10:38 am

Re: Retaining config values (.ini settings) when upgrading m

Post by sn260591 »

Code: Select all

class CoolStuffv2 expands Mutator config(MyCoolModv2);

var config bool bNoFirstRun;
var config int SomeSetting;

function PreBeginPlay()
{
	Super.PreBeginPlay();

	if (!bNoFirstRun && (DynamicLoadObject("MyCoolModv1.CoolStuffv1", Class'Class', true) != None))
	{
		SomeSetting = int(ConsoleCommand("get MyCoolModv1.CoolStuffv1 SomeSetting"));
		bNoFirstRun = true;
	}

	// Some code

	SaveConfig();
}
Last edited by sn260591 on Sun Jul 22, 2018 2:05 pm, edited 2 times in total.
schwap
Novice
Posts: 20
Joined: Thu Aug 25, 2016 1:06 am

Re: Retaining config values (.ini settings) when upgrading m

Post by schwap »

Use 'perObjectConfig' in the class parameters

http://mb.link-m.de/mirror/UndocumentedUC.htm
User avatar
Dizzy
Experienced
Posts: 109
Joined: Tue May 21, 2013 3:57 pm
Personal rank: Oaf
Contact:

Re: Retaining config values (.ini settings) when upgrading m

Post by Dizzy »

Both very interesting and informative replies - thank you!
Join the BunnyTrack.net Discord chat server: https://www.bunnytrack.net/discord
Post Reply