Changes

Jump to navigation Jump to search
→‎New C# utility methods: update for build 22342 (added random.GetChance)
Line 5,694: Line 5,694:  
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
! method
+
! <samp>ArgUtility</samp> method
 
! effect
 
! effect
 
|-
 
|-
Line 5,772: Line 5,772:  
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
! method
+
! <samp>Utility</samp> method
 
! effect
 
! effect
 
|-
 
|-
Line 5,793: Line 5,793:  
| <samp>GetDeterministicHashCode</samp>
 
| <samp>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.
 +
|}
 +
 +
And finally, it adds new extension methods:
 +
{| class="wikitable"
 +
|-
 +
! extension method
 +
! effect
 +
|-
 +
| <samp>random.GetChance</samp>
 +
| Perform a random probability check.
 +
 +
This just lets you simplify code like this:
 +
<syntaxhighlight lang="c#">
 +
if (Game1.random.NextDouble() < 0.8)
 +
</syntaxhighlight>
 +
Into a more semantic form:
 +
<syntaxhighlight lang="c#">
 +
if (Game1.random.GetChance(0.8))
 +
</syntaxhighlight>
 
|}
 
|}
  
translators
8,438

edits

Navigation menu