Ghost And Sword

Ghost And Sword

Enter in dark dungeons where the monsters rule are thirsty to kill you, collect items and artifacts, learn skills and fight with giant bossies, buy on earn gold new equipment and trade with lost souls.

Find the game on Gamejolt.

Config.js How to make config for mod.

How to make config for mod

Posted by on

First what is config is? Config is file that add options for users. Users not need edit config file, they just can press one button in mods menu and in mod configuration menu can select any options that you set for your mod.

To make it possible you need create config.js file inside your mod's folder.

Config comprises from two things: Options and variants.

Option is setting that have variants to set it on. For example: Option "Heal every turn" and variants "Yes" or "No". Player can select "Yes" or "No", and you will can check what variant chose user to call needed functions in your code.

Now lets go to practice:

Lets add one option

AddConfigOption(mod,'Cfg_Val','Test value',0);
  1. This is "mod" this always must be mod, because you need link config options to your mod.
  2. Cfg_value is just code name of your option, you will use this name to link variants to this option or to get result of what selected user.
  3. This visible name of option for user, this name will be display in configuration menu.
  4. This optional parameter, this parameter sets default data value of variant by index.

Now we need variants for this option

  1. This is "mod" this always must be mod, because you need link config options to your mod.
  2. Cfg_value this is code name of your option to which one you want to link this variant.
  3. This is visible name of this variant.
  4. This is data that will be return when this variant is selected.

This all! This was easy isn't it?

Now config is ready, but how to get selected variant?

You can do this with this one function:

GetConfigData(mod, option);

Use it in runtime.js of your mod and this will return selected variant's data of option.

Quick example:

if (IsActionTriggered("GameStart"))
   MakeMessage(mod, GetConfigData(mod, "Cfg_Val"))

Will return 1 or 2, depends of what selected player. If played selected nothing, config options will use default variant.


Join the community or sign in with your gaming account to join the conversation: