Modding:Options: Difference between revisions

875 bytes added ,  06:51, 30 July 2023
Add code examples
(Add image of example settings; reorganize Options.xml attributes into a table)
(Add code examples)
Line 48: Line 48:


==Using configured options in code==
==Using configured options in code==
Once you've added your own custom options, you can retrieve them in code using the <code>XRL.UI.Options.GetOption</code> method. This method always returns a string, but you may want to convert them into a different type before using them in your code. One way of doing so is to create a thin wrapper around <code>XRL.UI.Options</code> that calls <code>GetOption</code> under the hood, for instance:
<syntaxhighlight lang="csharp">
using System;
namespace MyName.MyMod {
    public class Options {
        private static string GetOption(string ID, string Default = "") {
            return XRL.UI.Options.GetOption(ID, Default);
        }
        public static bool EnableFoo => GetOption("Option_MyName_MyMod_EnableFoo").EqualsNoCase("Yes");
        public static int FooAmount => Convert.ToInt32(GetOption("Option_MyName_MyMod_FooAmount"));
    }
}
</syntaxhighlight>


{{Modding Navbox}}
{{Modding Navbox}}