Difference between revisions of "Modding Tutorials/TweakValue"

From RimWorld Wiki
Jump to navigation Jump to search
m
(Corrected section headers. =Top level= should never be used, it's reserved by the wiki for the page name.)
Line 3: Line 3:
 
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]
 
* [Setting up a Solution]
 
* [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 21: 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 31: 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]

Revision as of 22:16, 22 June 2020

Modding Tutorials

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

We are firmly in C# territory so you know

  • [Setting up a Solution]
  • [Custom code]

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.

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.

An Example

        [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

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;

See also

Method Reloader
Texture reloader