Changes

→‎Hash set fields: update for build 23289 (reverted mailbox change, removed Peek(), added other fields)
Line 43: Line 43:  
|-
 
|-
 
| <samp>Farmer</samp>
 
| <samp>Farmer</samp>
| <samp>achievements</samp><br /><samp>dialogueQuestionsAnswered</samp><br /><samp>eventsSeen</samp><br /><samp>mailbox</samp><br /><samp>mailForTomorrow</samp><br /><samp>mailReceived</samp><br /><samp>professions</samp><br /><samp>secretNotesSeen</samp><br /><samp>songsHeard</samp>
+
| <samp>achievements</samp><br /><samp>dialogueQuestionsAnswered</samp><br /><samp>eventsSeen</samp><br /><samp>mailForTomorrow</samp><br /><samp>mailReceived</samp><br /><samp>professions</samp><br /><samp>secretNotesSeen</samp><br /><samp>songsHeard</samp>
 
|-
 
|-
 
| <samp>FarmerTeam</samp>
 
| <samp>FarmerTeam</samp>
| <samp>broadcastedMail</samp>
+
| <samp>acceptedSpecialOrderTypes</samp><br /><samp>broadcastedMail</samp><br /><samp>completedSpecialOrders</samp><br /><samp>collectedNutTracker</samp>
 +
|-
 +
| <samp>Game1</samp>
 +
| <samp>worldStateIDs</samp>
 +
|-
 +
| <samp>NetWorldState</samp>
 +
| <samp>ActivePassiveFestivals</samp><br /><samp>CheckedGarbage</samp><br /><samp>FoundBuriedNuts</samp><br /><samp>IslandVisitors</samp><br /><samp>LocationsWithBuildings</samp>
 
|}
 
|}
   Line 52: Line 58:  
<ul>
 
<ul>
 
<li>Hash sets aren't ordered. For example, there's no guarantee that the first value when you enumerate it was the earliest one added.</li>
 
<li>Hash sets aren't ordered. For example, there's no guarantee that the first value when you enumerate it was the earliest one added.</li>
<li><p>Hash sets can't be indexed. For example, you can no longer use <code>list[0]</code> to get the first value. You can still enumerate them, but in most cases you should use methods like <samp>Add</samp> or <samp>Contains</samp> instead.</p>
+
<li><p>Hash sets can't be indexed. For example, you can no longer use <code>list[0]</code> to get the first value. You can still enumerate them or use LINQ methods like <samp>set.First()</samp>, but in most cases you should use the set methods like <samp>Add</samp> or <samp>Contains</samp> instead.</p>
    
To remove multiple matching values from the set, you can use <samp>RemoveWhere</samp> instead:
 
To remove multiple matching values from the set, you can use <samp>RemoveWhere</samp> instead:
 
<syntaxhighlight lang="c#">
 
<syntaxhighlight lang="c#">
 
// old code
 
// old code
for (int i = Game1.player.mailbox.Count - 1; i >= 0; i--)
+
for (int i = Game1.player.mailReceived.Count - 1; i >= 0; i--)
 
{
 
{
     if (Game1.player.mailbox[i].StartsWith("Example.ModId_"))
+
     if (Game1.player.mailReceived[i].StartsWith("Example.ModId_"))
         Game1.player.mailbox.RemoveAt(i);
+
         Game1.player.mailReceived.RemoveAt(i);
 
}
 
}
    
// new code
 
// new code
Game1.player.mailbox.RemoveWhere(id => id.StartsWith("Example.ModId_"));
+
Game1.player.mailReceived.RemoveWhere(id => id.StartsWith("Example.ModId_"));
 
</syntaxhighlight>
 
</syntaxhighlight>
  −
The game also adds a <samp>Peek()</samp> extension in the <samp>StardewValley.Extensions</samp> namespace to get the first value that would be enumerated. This is equivalent to the previous <samp>list[0]</samp>, except that the order may change when a value is added or removed.
   
</li>
 
</li>
 
<li>You no longer need to check before adding a value, since the hash set will ignore duplicates.</li>
 
<li>You no longer need to check before adding a value, since the hash set will ignore duplicates.</li>
<li>The <samp>Add</samp> or <samp>Remove</samp> values return whether a value was added/removed, which lets you check at the same time. For example:
+
<li>The <samp>Add</samp>/<samp>Remove</samp>/<samp>RemoveWhere</samp> methods return whether a value was added/removed, which lets you check at the same time. For example:
 
<syntaxhighlight lang="c#">
 
<syntaxhighlight lang="c#">
 
if (Game1.player.mailReceived.Add("BackpackTip")) // returns true if it wasn't in the set yet
 
if (Game1.player.mailReceived.Add("BackpackTip")) // returns true if it wasn't in the set yet
translators
8,404

edits