Difference between revisions of "Modding Tutorials/TweakValue"
(Created page with "{{BackToTutorials}} {{Stub}} TweakValue is a simple attribute that allows for direct run-time changing of values. They can be applied to any field with a value of float, bool...") |
|||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{BackToTutorials}} | {{BackToTutorials}} | ||
− | |||
TweakValue is a simple attribute that allows for direct run-time changing of values. They can be applied to any field with a value of float, bool, int or ushort that is static and isn't marked constant or readonly. | TweakValue is a simple attribute that allows for direct run-time changing of values. They can be applied to any field with a value of float, bool, int or ushort that is static and isn't marked constant or readonly. | ||
− | =Requirements= | + | ==Requirements== |
We are firmly in C# territory so you know | We are firmly in C# territory so you know | ||
− | * [Setting up a Solution] | + | * [[Modding Tutorials/Setting up a solution|Setting up a Solution]] |
− | * [Custom code] | + | * [[Modding Tutorials/Writing custom code|Custom code]] |
− | =What TweakValues are used for= | + | ==What TweakValues are used for== |
They really shine in creating UI. If you need to nudge an element just a smidgen to the left, you'd normally have to edit, recompile and restart the game. With a TweakValue, you can call forth a menu with sliders and immediately see the effects of our changes. | They really shine in creating UI. If you need to nudge an element just a smidgen to the left, you'd normally have to edit, recompile and restart the game. With a TweakValue, you can call forth a menu with sliders and immediately see the effects of our changes. | ||
− | =Using your TweakValues= | + | ==Using your TweakValues== |
It's one of the dev-mode buttons. Looks kinda like a list of dashes and dots. Slide it around for funsies. TweakValues are not stored anywhere. If you find a good value, write it down as they are lost for all eternity when the game closes. | It's one of the dev-mode buttons. Looks kinda like a list of dashes and dots. Slide it around for funsies. TweakValues are not stored anywhere. If you find a good value, write it down as they are lost for all eternity when the game closes. | ||
− | =An Example= | + | ==An Example== |
<source lang = "C#"> | <source lang = "C#"> | ||
[TweakValue("exampleCategory", -100f, 4000f)] | [TweakValue("exampleCategory", -100f, 4000f)] | ||
Line 22: | Line 21: | ||
Simple as that. ''exampleCategory'' is a string that's shown in the TweakValues window. The numbers inside the annotation are optional min and max values (default 0 and 100 respectively). | Simple as that. ''exampleCategory'' is a string that's shown in the TweakValues window. The numbers inside the annotation are optional min and max values (default 0 and 100 respectively). | ||
− | =Tips= | + | ==Tips== |
Put your [TweakValue] in an #if DEBUG or comment them out for release. This prevents spamming the TweakValues window. The TweakValue window is organised alphabetically, so if you categorise your values sensible and with AAA you'll save yourself some scrolling. | Put your [TweakValue] in an #if DEBUG or comment them out for release. This prevents spamming the TweakValues window. The TweakValue window is organised alphabetically, so if you categorise your values sensible and with AAA you'll save yourself some scrolling. | ||
Line 32: | Line 31: | ||
</source> | </source> | ||
− | =See also= | + | ==See also== |
[https://github.com/pardeike/Reloader Method Reloader]</br> | [https://github.com/pardeike/Reloader Method Reloader]</br> | ||
[https://github.com/RimWorld-CCL-Reborn/RWTextureReload Texture reloader] | [https://github.com/RimWorld-CCL-Reborn/RWTextureReload Texture reloader] | ||
+ | |||
+ | |||
+ | [[Category:Modding tutorials]] |
Latest revision as of 01:31, 24 July 2024
TweakValue is a simple attribute that allows for direct run-time changing of values. They can be applied to any field with a value of float, bool, int or ushort that is static and isn't marked constant or readonly.
Requirements[edit]
We are firmly in C# territory so you know
What TweakValues are used for[edit]
They really shine in creating UI. If you need to nudge an element just a smidgen to the left, you'd normally have to edit, recompile and restart the game. With a TweakValue, you can call forth a menu with sliders and immediately see the effects of our changes.
Using your TweakValues[edit]
It's one of the dev-mode buttons. Looks kinda like a list of dashes and dots. Slide it around for funsies. TweakValues are not stored anywhere. If you find a good value, write it down as they are lost for all eternity when the game closes.
An Example[edit]
[TweakValue("exampleCategory", -100f, 4000f)] private static float exampleFloat = 2000f;
Simple as that. exampleCategory is a string that's shown in the TweakValues window. The numbers inside the annotation are optional min and max values (default 0 and 100 respectively).
Tips[edit]
Put your [TweakValue] in an #if DEBUG or comment them out for release. This prevents spamming the TweakValues window. The TweakValue window is organised alphabetically, so if you categorise your values sensible and with AAA you'll save yourself some scrolling.
#if DEBUG [TweakValue("AAAMehniMiscMods")] #endif private static float widthFiddler = 9f;