Changes

Jump to navigation Jump to search
→‎New C# utility methods: update for build 23182 (added Utility.WrapIndex)
Line 7,777: Line 7,777:  
| <samp>Utility.GetDeterministicHashCode</samp>
 
| <samp>Utility.GetDeterministicHashCode</samp>
 
| ''(Specialized)'' Get a [https://en.wikipedia.org/wiki/Hash_function hash code] which is always the same for a given input (unlike [https://learn.microsoft.com/en-us/dotnet/api/system.object.gethashcode <samp>string.GetHashCode()</samp>]), even if you restart the game or play on another computer. For example, this ensures that randomized shop items are the same across all players in multiplayer and don't change when you reload the save.
 
| ''(Specialized)'' Get a [https://en.wikipedia.org/wiki/Hash_function hash code] which is always the same for a given input (unlike [https://learn.microsoft.com/en-us/dotnet/api/system.object.gethashcode <samp>string.GetHashCode()</samp>]), even if you restart the game or play on another computer. For example, this ensures that randomized shop items are the same across all players in multiplayer and don't change when you reload the save.
 +
|-
 +
| <samp>Utility.WrapIndex</samp>
 +
| Constrain an index to a range by wrapping out-of-bounds values to the other side (e.g. last index + 1 is the first index, and first index - 1 is the last one).
 +
 +
For example:
 +
<syntaxhighlight lang="c#">
 +
string[] values = new[] { "0", "1", "2" };
 +
int index = Utility.WrapIndex(-1, values.Length); // 2
 +
</syntaxhighlight>
 
|}
 
|}
  
translators
8,445

edits

Navigation menu