ShopData may return unknown error if key does not exist
Closed this issue · 1 comments
If item.itemKey
does not exist in the dictionary, count
will be false
. This is what TryGetValue
is supposed to do, however, the error is not caught.
Then, this._itemCounts[item.ItemKey] = count + 1
will cause two exceptions:
- item.ItemKey does not exist
- cannot add "1" to
false
GetCount()
will return false
if the key does not exist, which will cause an error because the return type is int
and not <Nullable>int
.
Check if the value exists, and if it does then use it: https://msdn.microsoft.com/en-us/library/bb347013%28v=vs.110%29.aspx
File: https://github.com/Yonom/BotBits/blob/master/BotBits/Helpers/PlayerData/ShopData.cs#L15
I'm not too familiar with returning/setting enums as null so the following examples may be okay. If they are, disregard them:
BotBits/BotBits/Models/CampaignReward.cs
Line 12 in e49a7b2
An int cannot be "false", it is 0 by default. The result value of TryGetValue is ignored and this is done intentionally. You can indeed add 1 to 0.
item.ItemKey does not need to exist for me to be able to set it's value, it will just add a new item to the dictionary in this case.
Enums are valuetypes and cannot be null, the functions will return their default value.
Invalid issue, cannot reproduce. Closed.