12/26/14, 11:26 PM | #1 |
|
GetItemType() ?
Maybe not a bug, just an unwanted (by me) default action...
I'm trying to track down an error causing a crash. This is not the cause, but its something I noticed when trying to tack down the problem. In my code I have been checking to see if an item exists in a bag/slot by checking the itemType before attempting to do anything with the item. If it came back ITEMTYPE_NONE I assumed the item was moved, destroyed, sold, or I assumed it was just an invalid bag/slot passed in. But I just found out that
Is there any other way to verify if the values for bag/slot are valid & correspond to an actual item that still exists in that bag/slot? (besides tediously checking the bag# & slot# against the available bags & slots) Last edited by circonian : 12/26/14 at 11:41 PM. |
12/27/14, 06:52 AM | #2 |
I think that the easiest solution is checking if arguments are valid before you use them.
Lua Code:
This is how it does inventory manager: Lua Code:
Global reference to that function is PLAYER_INVENTORY:IsSlotOccupied(bagId, slotIndex) Last edited by Garkin : 12/28/14 at 06:27 AM. Reason: Typo, variable i should be slotIndex. |
|
12/27/14, 07:28 PM | #3 | |
|
Thanks for the help Garkin. |
|
12/28/14, 10:08 PM | #4 |
|
One more question about this, mainly its out of curiousity as to why this is happening.
I took your suggestion & started using: Lua Code:
But after I call that to check I'm trying to grab the slot data like this, but I'm getting an error sometimes: Lua Code:
So if the IsBagSlotOccupied(..) returns true, then there is an item in that bag slot. and this Lua Code:
I "think" its only occuring when I move items...but still if the slot is occupied I was assuming the bag/slot did not belong to an empty slot the item was moved out of, so there should still be data there? The only thing I can think of now is to add another check to make sure the slotData is valid also. Lua Code:
Any ideas why this happens? |
12/29/14, 10:19 AM | #5 |
|
Why not check only slotData. The whole IsBagSlotOccupied check seems redundant (and also overly tolerant to invalid input if you ask me )
|
12/29/14, 06:56 PM | #6 | |
|
I don't remember now, I think the problem was that they were nil. So I could have "just" checked to ensure they are not nil, but I wasn't sure if any other invalid values would also throw an error so I thought the best method would be to just check to make sure the bag/slot are ones that I know are valid, which worked. But the slotData could still come out nil so had to check it too. Redundant, I agree!! I dunno maybe your right it, is overly tolerant. Its their own fault if they pass in bad values to start with. |
|
12/29/14, 11:45 PM | #7 |
As merlight said, if you are going to use function SHARED_INVENTORY:GenerateSingleSlotData(bagId, slotIndex), much easier (and faster) is just checking data you get from this function.
Lua Code:
At first I wanted to add condition "slotData.stackCount > 0" to the function above, but it is not necessary. SHARED_INVENTORY checks it before storing slot data into the bag cache, so stackCount must be always more then zero. Q: When slotData could be nil even if slot is not empty? A: If you are using SHARED_INVENTORY:GenerateSingleSlotData(bagId, slotIndex) directly from the EVENT_INVENTORY_SINGLE_SLOT_UPDATE handler, it is possible that your function is called before bag cache is updated. If you want to be sure that cache is updated, use SHARED_INVENTORY's callbacks instead. Example: Lua Code:
|
|
12/30/14, 12:42 AM | #8 | |
|
At first I had was worried if another addon called it with invalid bag/slot and then, yes, in my addon it was getting called from EVENT_INVENTORY_SINGLE_SLOT_UPDATE which is when I ran into the second problem with GenerateSingleSlotData(..) coming back nil. I didn't realize I could register for a "SingleSlotInventoryUpdate" for the SHARED_INVENTORY. Thanks for the info. |
|
ESOUI » Developer Discussions » General Authoring Discussion » GetItemType() Bug? |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|