11/18/14, 10:08 AM | #1 | |
brekal
Guest
Posts: n/a
|
FindFirstEmptySlotInBag not updating
Hey guys it's me again ;-)
I have some issues with the function FindFirstEmptySlotInBag(BAG_BACKPACK). I want to move items from the bank into my inventory but it always just moves one item. I dumped the values of the variables and found out that the Destination SlotID (slotId_Bag) always stays the same. So I think that this is the issue - but unfortunately I cannot image why it is not updating because I call it in every loop of the for-loop so it should update correctly. Lua Code:
Do you see any error here? Thanks in advance |
|
brekal |
11/18/14, 11:03 AM | #2 |
|
That's probably by design. The items are not actually moved immediately, your commands are carried out after your handler exits.
Some time ago I wrote my own function for finding an empty slot, which allows me to start the search after the previous one: Lua Code:
|
11/18/14, 12:29 PM | #3 | |
brekal
Guest
Posts: n/a
|
Thanks for your reply.
I already thought about making my own Slotfinder but i hoped that there was some working built-in function .... |
|
brekal |
11/18/14, 09:15 PM | #4 |
|
I'm pretty sure the keys in the slots table matches the slotIndices. So you could loop through the slots and check to see if each key exists in the table.
Lua Code:
Or you could make it into a function and each time you find an empty slot throw it into a table, then return the table & you'll have all of the empty slots to do whatever you want with them. Although merlights answer is probably better for what your doing, just giving some options. |
11/18/14, 10:05 PM | #5 |
This issue is because of 500ms delay in you function LootManager.MoveItems. All calls of the FindFirstEmptySlotInBag within this 500ms will return still the same slot. If you remove zo_callLater from the function, it should work correctly.
And I think it will be better if you use RequestMoveItem function instead of PickupInventoryItem and PlaceInInventory functions. |
|
11/19/14, 05:59 AM | #6 | |
|
Similar thing happens if you handle EVENT_LOOT_UPDATED. Functions GetLootMoney/GetNumLootItems will keep returning the values applicable when the handler was called, even after you call LootMoney/LootItemById inside the handler. After the handler exits, items are actually moved, and a new event generated with updated state. Good point, this one was added recently. And has a better name - request indicates the action is not carried out immediately. |
|
11/19/14, 10:31 PM | #7 | |
|
Lua Code:
What is the purpose of the delay? If you're trying to not flood the server (which could result in a forced logout), it doesn't work as written. zo_callLater is non-blocking, so it will exit the main function and continue in the loop without waiting at all. You'll end up with all the actual move attempts ~500ms later still close enough to flip a message rate limit. |
|
11/20/14, 03:14 AM | #8 | |
brekal
Guest
Posts: n/a
|
thanks for your replies.
First I tried out circonians suggestion - but unfortunately it didn't work. So I tried his second suggestion - to go through the inventory and save all free slots in an extra table. When I then move the item I iterate through the table of free stlots. I had there some issues too. Because when I started at the first element sometimes it did not get the right destSlots. So I decided to start at the last element and this works fine. I know that my solution is not the smartest but at least it is working for my purposes Here ist the actual code: Lua Code:
I also do not understand why this delay should cause the problem because I only delay the movement of the item, not the FindFirstEmptySlotInBag-function. The interesting thing about this is, that dumping the values (as I do in line 44 and 45 of my original post) shows the correct item name and srcSlot - the only thing that stays the same is the destSlot. I did not find any article on esoui-wiki about this "RequestMoveItem" function that Garkin suggested - do you have more infos about it? |
|
brekal |
11/20/14, 10:05 AM | #9 |
|
Adding delay is unnecessary, the move won't happen until your handler exists anyway.
Haven't really tested it, but I'm pretty sure the client doesn't do any network communication directly from API functions. Think about it - if you called RequestMoveItem and the client would immediately send the request to the server, waited for the response and then returned the result to you, the latency would be horrid, and your add-on would completely block all other add-ons for the duration of the request (by all other add-ons I mean the whole UI, health bars and such). API functions absolutely have to put network requests on a queue. Then I have some design notes on your free slots caching: 1) You don't know in advance how many free slots you're going to need. Thus finding all of them before you start is a bit wasteful. The function I posted earlier looks for one free slot, you call it when you need one. This is a somewhat generic principle: don't search and cache everything you might need later, search and cache things you actually need. 2) Check whether a slot is empty using something other than GetItemName (comparing strings will always be slower than comparing numbers). I used GetItemType for that. edit: 3) you probably wanted slotId_Bag = table.remove(LootManager.emptySlotsInBag); your code doesn't really take items from the cache, it uses the same 1-4 slots over and over. From ESOUIDocumentationP5.txt (you can find it on official forums in PTS section) * RequestMoveItem *protected* (*integer* _sourceBag_, *integer* _sourceSlot_, *integer* _destBag_, *integer* _destSlot_, *integer* _stackCount_) Last edited by merlight : 11/20/14 at 10:12 AM. |
11/20/14, 01:47 PM | #10 | |
|
Also as merlight stated it is wasteful to loop through and find ALL of the free slots available if you do not need them all. As I stated above, merlights answer is definitely better. I was only trying to give some options on ways you can find free slots, without copying his answer because I could not think of a better one and figured who knows sometime it may be useful to find all of the free slots for you or someone else reading this later. Sorry if I did not make my reply clear enough. |
|
11/20/14, 02:04 PM | #11 | |
|
But, Is there a reason you don't just check the inventory slots table instead of calling GetItemType and comparing it to see if its ITEMTYPE_NONE? Wouldn't that be even faster? Lua Code:
|
|
11/20/14, 03:29 PM | #12 | |
|
No particular reason. GetItemType is what I learned first, is easy to remember and also shorter, dunno about speed Although if you wanted to use pre-cached slot data, you should probably use SHARED_INVENTORY:GenerateSingleSlotData. That's what PLAYER_INVENTORY.inventories[iInventory].slots are initialized with: Lua Code:
|
|
10/28/15, 05:50 PM | #13 |
A very old bump for 1st thank you for this feedback
I personnally wrote this : Lua Code:
But this function is not the only one to do not update in real time, a second one, more recent got the same problem : GetItemLinkStacks(itemLink) My solution is : Lua Code:
An exemple : Code:
[00:38:18] -------------- [00:38:18] 672 -- backpackqty with mycache func [00:38:18] 500 -- bankqty with mycache func [00:38:18] --- [00:38:18] 672 -- backpackqty with ZOS func [00:38:18] 500 -- bankqty with ZOS func [00:38:18] -------------- [00:38:18] BMR a déplacé 72x [Toile du Vide] en banque <----- my addon moved 72x from bag to bank [00:38:18] -------------- [00:38:18] 600 -- backpackqty with mycache func [00:38:18] 572 -- bankqty with mycache func [00:38:18] --- [00:38:18] 672 -- backpackqty with ZOS func -- Wrong [00:38:18] 500 -- bankqty with ZOS func -- Wrong [00:38:18] -------------- [00:38:18] BMR a déplacé 28x [Toile du Vide] en banque <----- my addon moved 28x from bag to bank (from another stack, approx 1ms after 1st move [00:38:18] -------------- [00:38:18] 572 -- backpackqty with mycache func [00:38:18] 600 -- bankqty with mycache func [00:38:18] --- [00:38:18] 672 -- backpackqty with ZOS func -- Wrong [00:38:18] 500 -- bankqty with ZOS func -- Wrong [00:38:18] -------------- |
|
ESOUI » Developer Discussions » Lua/XML Help » FindFirstEmptySlotInBag not updating |
«
Previous Thread
|
Next Thread
»
|
Thread Tools | |
Display Modes | |
|
|