Jump to content

Configurable Dark Sword


Recommended Posts

To make something configurable, you add an option in configuration_options in modinfo.

Example:

configuration_options =
{
	{
		name = "start_dark_sword",
		label = "Start With Dark Sword",
		options = {
			{description = "Yes", data = true},
			{description = "No", data = false}
		},
		default = true,
	},
}

Now we retrieve in modmain, the value of the configuration:

GLOBAL.TUNING.WAFFLES_START_WITH_DARK_SWORD = GetModConfigData("start_dark_sword")

and we store it in the tuning table of the game with a unique identifier.

Now in our character prefab we have access to that value in the tuning table.

For example, my character starts with two meat, and one optional dark sword:

local start_inv = {
	"meat",
	"meat",
}

if TUNING.WAFFLES_START_WITH_DARK_SWORD then
	table.insert(start_inv, "nightsword")
end

If the value stored is true, then we get a sword in our starting inventory.

start_inv is a parameter of the MakePlayerCharacter function at the end of our character prefab file.

return MakePlayerCharacter("waffles", prefabs, assets, common_postinit, master_postinit, start_inv)

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...