Changes

Jump to navigation Jump to search
→‎Inventory class: add migration notes for matches by name
Line 2,673: Line 2,673:  
! migration
 
! migration
 
|-
 
|-
|rowspan="5"| <samp>Farmer</samp>
+
|rowspan="6"| <samp>Farmer</samp>
| <code>getItemCount(id)</code><br /><code>GetTallyOfObject(id)</code><br /><code>GetTallyOfObject(id, isBigCraftable)</code><br /><code>hasItemInInventory(id, count)</code><br /><code>hasItemInInventoryNamed(name)</code><br /><code>hasItemInList(list, id, count)</code><br /><code>hasItemWithNameThatContains(name)</code>
+
| <code>getItemCount(id)</code><br /><code>GetTallyOfObject(id)</code><br /><code>GetTallyOfObject(id, isBigCraftable)</code><br /><code>hasItemInInventory(id, count)</code><br /><code>hasItemInList(list, id, count)</code>
 
| &#32;
 
| &#32;
 
* To check an item ID, use <code>items.CountId(id)</code> or <code>Items.ContainsId(id, count)</code>.
 
* To check an item ID, use <code>items.CountId(id)</code> or <code>Items.ContainsId(id, count)</code>.
 
* To check Golden Walnuts or Qi Gems, use the <samp>Game1.netWorldState.Value.GoldenWalnuts</samp> and <samp>Farmer.QiGems</samp> fields.
 
* To check Golden Walnuts or Qi Gems, use the <samp>Game1.netWorldState.Value.GoldenWalnuts</samp> and <samp>Farmer.QiGems</samp> fields.
 
* To check category matches or <samp>-777</samp> (seasonal wild seeds), the <samp>getItemCount</samp> and <samp>getItemCountInList</samp> still exist.
 
* To check category matches or <samp>-777</samp> (seasonal wild seeds), the <samp>getItemCount</samp> and <samp>getItemCountInList</samp> still exist.
 +
|-
 +
| <code>hasItemInInventoryNamed(name)</code><br /><code>hasItemWithNameThatContains(name)</code>
 +
| In most cases, you should match items by ID instead (see the previous row).
 +
 +
If you really need to match items by name, you can replace it like this:
 +
<syntaxhighlight lang="c#">
 +
// exact name
 +
bool hasMatch = Game1.player.Items.Any(p => p?.Name == name);
 +
 +
// name contains
 +
bool hasMatch = Game1.player.Items.Any(p => p?.Name?.Contains(name) is true);
 +
</syntaxhighlight>
 
|-
 
|-
 
| <code>areAllItemsNull()</code>
 
| <code>areAllItemsNull()</code>
translators
8,438

edits

Navigation menu