Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is an API that I created to help facilitate new ModOptions in the new system.
While the new system is easy to use, it can be simpler!
Features:
NOTE: Options are not guaranteed populated until event "OnInitGlobalModData", which is called when starting an actual game.
Usage:
If this is accepted, I will also update my B42 ModOptions example on the Workshop to include an example as well.
In a new file in your mod (we'll name it "MyConfig.lua"), add the following:
The
Build()
function is required, and will be called by the ModOptionsAPI "OnGameBoot" to populate the available options set by your mod.The
Apply()
function is optional, and can be removed from the file if it is not needed. However, you can use this to run things while you are in game to accommodate for the option changes.In your mod, add the following:
Now you can directly access any of your options with simply:
Where "ID" is the ID that you specified when creating each option. Using the above example:
Multi-checkbox options are unique, in that the
getValue
function also requires the index. When parsing the options for these, I opted to append the index to the end of the ID you created.Given:
These would be available as:
Sandbox
For Sandbox variable support, add the Sandbox namespace to end end of the ":new()" function:
Any Sandbox options are now available in our
config
table when in-game automatically.For example, given:
The namespace in the above is "B42ModOptions".
This will be available in game as:
Supports the
OnSandboxOptionsChanged
created by Change Sandbox Options (by Star), so a change in Sandbox Options in Single Player is propagated immediately. TheApply()
function is called in these cases as well.