and as I was typing this, the error happened again. Yay!
I have to study this because right now it's the only clue I have.Code:------------------------------------------------------------ McGuffinpunk 2.9 5/7/2025 1:44:43 AM Wild Items.Add(Public Sub) ------------------------------------------------------------ Error Details: Error 'This key is already associated with an element of this collection' (Error Number: 457) occurred in Wild Items.Add(Public Sub). Error Number: 457 Parameters and Associated Objects: Carbon Steel Industry Waist 1
It was in the Backpack, lost and it says it's trying to add it to Backpack. But the output says it was in the Backpack and trying to add it to WildItems.
But the error is in BackpackItems.
Does it think the WildItems are the Backpack? If so then I have bigger problems than I thought.
It began with stealing it. Then somehow it got "Lost" twice which tells me it's the Lost item thing that might be the problem. It's not really getting lost.
I have it set to break on all errors so I can see if it's always the same chain of events which is what I'm hoping for.
This is from the Viewer Window with stats irrelevant to the problem snipped out.
I will continue with the above in a follow up post.Code:Carbon Steel Industry Waist 1 Details: Item Slot: Waist Minimum Deck to Equip: 8 Current Location: Wild Items Source: Backpack Acquisition Method: Lost Add to Items: Failed x Found: 0 x Gifted: 0 x Purchased: 0 x Sold: 0 x Lost: 2 <--- Lost two times. x Stolen: 1 <--- But only Acquired one time. x Caught Stealing: 0 x Equipped: 2 x Used: 2,922 ------------------------------------
------------------------------ This is where I actually started this post until the above error interrupted.
I posted some of this code last week.
I don't know when the bug was introduced. It may have already been there last week when I posted the code but it never came up until I made a lot of changes.
This is what's going on.
The issue is with the Backpack specifically having an Item it shouldn't (the Item was supposedly transferred out of the Backpack) which raises an error when attempting to place that Item in the Backpack later.
The Item is now in two places at the same time - the Backpack and wherever it was transferred.
It can take hours or days from the time the error is created until it is raised.
In the mean time that item can be randomly bought, sold, lost, found and all that over and again before it finds its way back into to the backpack when the error is raised
This is the abridged output to the error log:
There three ways to transfer an Item from the Backpack; Equip, Sell or Lose.Code:------------------------------------------------------------ McGuffinpunk 2.9 5/6/2025 8:32:57 AM Error 'This key is already associated with an element of this collection' (Error Number: 457) occurred in Backpack Items.Add(Public Sub). ------------------------------------------------------------ McGuffinpunk 2.9 5/6/2025 10:45:28 AM Error 'This key is already associated with an element of this collection' (Error Number: 457) occurred in Backpack Items.Add(Public Sub). ------------------------------------------------------------ McGuffinpunk 2.9 5/6/2025 2:56:00 PM Error 'This key is already associated with an element of this collection' (Error Number: 457) occurred in Backpack Items.Add(Public Sub). ------------------------------------------------------------ and so on... taking place over several hours.
So that's where I need to be looking.
But I suppose I could accidentally be putting an Item in the Backpack at the same time I'm putting it somewhere else. I think it's the transfer though.
I've gone over the code for a couple days step by step through every single procedure and can't figure out where it's happening
This code is updated from what I posted last week but is not current.
So I've updated the code to what follows.Code:' BAS Module. Private Function TransferItem(ByRef Item As cItem, ByRef FromItems As cItems, ByRef ToItems As cItems) As Long If Not ValidObject(Item) Then Exit Function If Not ValidObject(FromItems) Then Exit Function If Not ValidObject(ToItems) Then Exit Function FromItems.Remove Item If (FromItems Is EquippedItems) And (Item.DestroyOnUnequip = vbChecked) Then DestroyedItems.Add Item Else ToItems.Add Item End If TransferItem = 1 End Function ' cItems Class Public Sub Add(ByRef Item As cItem) On Error GoTo errHandler If Not ValidObject(Item) Then Exit Sub colItems.Add Item, CStr(Item.Name) Item.AddTrail Me.Name RaiseEvent ItemAdded(Item) Exit Sub errHandler: ErrorHandler Error, Err, Item.Name, Name & ".Add(Public Sub)" AddMessage Item.Trail, vbNullString, -1, idx_MessageWindow_System End Sub
I can better trace the Item this way and know how it got to where it is. Or at least reduce my search radius and maybe make it even more refined if I need to.
I already had an Item Trail built in to the Item Class but it only added its new location to the trail with no indication of how it got there.
Obviously there's a whole trail of code that gets to here but that will be a lot to post.Code:' BAS Module. Public Enum ITEM_SOURCE_INDEX idx_ItemSource_BackpackItems idx_ItemSource_DestroyedItems idx_ItemSource_EquippedItems idx_ItemSource_ItemRegistry idx_ItemSource_ItemShuffler idx_ItemSource_VendorItems idx_ItemSource_WildItems End Enum Public Enum ACQUISITION_METHOD_INDEX idx_AcquisitionMethod_Find idx_AcquisitionMethod_Gift idx_AcquisitionMethod_Lose idx_AcquisitionMethod_Purchase idx_AcquisitionMethod_Sell idx_AcquisitionMethod_Shuffle idx_AcquisitionMethod_Steal idx_AcquisitionMethod_Transfer ' Backpack to Equipped or vice-versa. End Enum Private Function TransferItem(ByRef Item As cItem, ByRef FromItems As cItems, ByRef ToItems As cItems, ByRef AcquisitionMethodID As ACQUISITION_METHOD_INDEX) As Long If Not ValidObject(Item) Then Exit Function If Not ValidObject(FromItems) Then Exit Function If Not ValidObject(ToItems) Then Exit Function FromItems.Remove Item If (FromItems Is EquippedItems) And (Item.DestroyOnUnequip = vbChecked) Then If Item.TimesUsed = 0 Then ItemRegistry.Remove Item Set Item = Nothing Else DestroyedItems.Add Item, FromItems.ItemSourceID, AcquisitionMethodID End If Else ToItems.Add Item, FromItems.ItemSourceID, AcquisitionMethodID End If TransferItem = 1 End Function ' cItems Class. Public Sub Add(ByRef Item As cItem, ByRef ItemSourceID As ITEM_SOURCE_INDEX, ByRef AcquisitionMethodID As ACQUISITION_METHOD_INDEX) On Error GoTo errHandler If Not ValidObject(Item) Then Exit Sub colItems.Add Item, CStr(Item.Name) Item.AddTrail Me.Name & vbCrLf & "Source: " & ItemSourceText(ItemSourceID) & vbCrLf & "Acquisition Method: " & AcquisitionMethodText(AcquisitionMethodID) & "Add to Items: Success" RaiseEvent ItemAdded(Item) Exit Sub errHandler: ErrorHandler Error, Err, Item.Name, Name & ".Add(Public Sub)" Item.AddTrail Me.Name & vbCrLf & "Source: " & ItemSourceText(ItemSourceID) & vbCrLf & "Acquisition Method: " & AcquisitionMethodText(AcquisitionMethodID) & "Add to Items: Failed" AddMessage Item.Trail, vbNullString, -1, idx_MessageWindow_System ListItemEffects Item, idx_MessageWindow_Viewer End Sub
Also too, I made a lot of the stuff I posted last week more granular.
So instead of when Buying an Item you first got a shot at it being a gift, then if not you would purchase if if you can afford it and if not then try to steal it.
That's all separate stuff now starting here:
Code:Private Function Random08() As Long Dim m_DnD As cDoNotDisturb Dim m_NGS As cNormalizeGameSpeed Const COOL_DOWN As Long = 60 Const DIE_SIDES As Long = d6 Static dLastEvent As Date ' Anything to do with Items goes here. If DoNotDisturb Then Exit Function If ElapsedSeconds(dLastEvent) < COOL_DOWN Then Exit Function Set m_DnD = New cDoNotDisturb Set m_NGS = New cNormalizeGameSpeed m_NGS.DecelerationEvent = idx_DecelerationEvent_Items Select Case RollFor("Stuff", DIE_SIDES, idx_MessageWindow_Notification) Case 1: Random08 = GetFreeItem ' Free Item. Includes Finding Random Items, Gifts and Stealing. Case 2: Random08 = BuyItem ' Buy Item. Case 3: Random08 = LoseItem ' Lose Item. Can be from EquippedItems or BackpackItems Case 4: Random08 = SellItem ' Sell Item. Can be from EquippedItems or BackpackItems Case Else: Random08 = FidgetItem ' Create or Move Items (no loss or gain to Player). End Select If Random08 <> 1 Then Exit Function dLastEvent = Now() End Function Private Function GetFreeItem() As Long Select Case RollFor("Free Stuff", d3, idx_MessageWindow_Notification) Case 1: GetFreeItem = TryFindRandomItem Case 2: GetFreeItem = TryGiftRandomItem(VendorItems) Case 3: GetFreeItem = TryStealRandomItem(VendorItems) End Select End Function Public Function TryGiftRandomItem(ByRef FromItems As cItems) As Long Dim m_Item As cItem If Not ValidObject(FromItems) Then Exit Function Set m_Item = RandomItem(FromItems) If Not ValidObject(m_Item) Then Exit Function If TryRollForItem(m_Item, "Receive a Gift", "They're not that into you.") <> 1 Then Exit Function With m_Item .TimesGifted = .TimesGifted + 1 AddMessage AddAsterisks("A " & .Name & " was given to you!"), vbTab, 0, idx_MessageWindow_Primary End With EquipStoreOrSellItem m_Item, FromItems, idx_AcquisitionMethod_Gift, False TryGiftRandomItem = 1 End Function Private Function TryRollForItem(ByRef Item As cItem, ByRef RollForText As String, ByRef FailText As String) As Long Dim nDieSides As Long If Not ValidObject(Item) Then Exit Function Select Case RollForCritical(RollForText) Case idx_CriticalRoll_Success ' Do nothing. Case idx_CriticalRoll_Fail AddMessage AddAsterisks(FailText), vbTab, 0, idx_MessageWindow_Primary Exit Function Case Else nDieSides = LevelRequirementDieSides(Item.LevelRequirement) If RollDie(nDieSides) <> nDieSides Then AddMessage AddAsterisks(FailText), vbTab, 0, idx_MessageWindow_Primary Exit Function End If End Select TryRollForItem = 1 End Function




Reply With Quote