-
Notifications
You must be signed in to change notification settings - Fork 4
Home
First create your script file that be used to create and manage your config files. In this example we will name it ExampleModConfig.gd
- While you can do this in your
Main.gdscript I recommend creating a separate file to keep it clutter free - Make sure to place
extends Nodeat the top of the script
ExampleModConfig.gd
extends Node
func _ready():
passAdd your config file to the mod.txt file under the [Autoload] section. This allows the script to be ran as the game first loads so your config file can be created/loaded before anything accesses it.
- Make sure the path has the correct folder structure to point to the script just like your
Main.gdscript
mod.txt
[Autoload]
ExampleConfig="res://ModConfigruationMenu/ExampleModConfig.gd"There are 2 constants that should be defined at the top of your config script to make config creation and registration easier. They are:
-
MOD_ID- A unique identifier for your mod's configuration registration. This does not need to be the same as yourmod.txtid -
FILE_PATH- This is the file path that your config file(s) will be stored. It is very important that your config files be saved at"user://MCM/{MOD_ID}/"
ExampleModConfig.gd
extends Node
const MOD_ID = "ExampleMod"
const FILE_PATH = "user://MCM/ExampleMod"
func _ready():
passIn the _ready() function
- Create variable and store the ConfigFile class in it:
var _config = ConfigFile.new() - Using
FileAccesscheck to see if the config file exists:if !FileAccess.file_exists(FILE_PATH + "/config.ini") - Start setting your config values within your config variable:
_config.set_value(...)- There is a very specific way these values need to be stored. We will go over this shortly
- After setting all your values we need to create the folder, using
DirAccess, where the config files will be stored: `DirAccess.open("user://").make_dir(FILE_PATH) - Save the config file to the system: `_config.save(FILE_PATH + "/config.ini")
MCM_Helper.gd is the main file you as a mod author will be using to register your config file with MCM. It holds a handful of helper functions that's used within the mod itself but only 1 that you need to worry about.
The ReigsterConfiguration
In order for you to register your mod with MCM you must load the MCM_Helpers.tres file. To do this place this line at the top of your script below the extends Node line: var McmHelpers = preload("res://ModConfigurationMenu/Scripts/Doink Oink/MCM_Helpers.tres")
ExampleModConfig.gd should now look like this
extends Node
var McmHelpers = preload("res://ModConfigurationMenu/Scripts/Doink Oink/MCM_Helpers.tres")
func _ready():
pass