-   AddOn Help/Support (
-   -   While loop breaking ESO (

MethosFrost 10/26/19 01:25 AM

While loop breaking ESO
I'm slowly working on an addon that includes auto refining and I'm having an issue with the while loop locking up ESO completely. Has anyone seen this type of issue or can someone smarter than me think of a way around the issue? Everything in this code works until I uncomment the (while do end) and I get the expected array count on the testing output.

NOTE-- I added the table remove to find a way around this issue thinking the array wasn't empty.

Lua Code:
  1. local function RefineKey()
  2.     local function createList()
  3.     local readyRefine = {}
  4.         if not GetRefineItems(BAG_BACKPACK) then readyRefine = false end
  5.         if HasCraftBagAccess() then
  6.             if not GetRefineItems(BAG_VIRTUAL) then readyRefine = false end
  7.         end
  9.         if AllCraft_Decon.deconSettings.UseBank then
  10.             if not GetRefineItems(BAG_BANK) then readyRefine = false end
  11.             if IsESOPlusSubscriber() then
  12.                 if not GetRefineItems(BAG_SUBSCRIBER_BANK) then
  13.                     readyRefine = false
  14.                 end
  15.             end
  16.         end
  17.         --**ToBeAdded** check for array add failures.
  18.     end
  19.     createList()
  20.     --**ToBeAdded** reiterate createList as many times as needed to empty all bags.
  21.     d(#RefineList)
  22.     --while #RefineList ~= 0 do
  23.         PrepareDeconstructMessage()
  24.         for index, thing in ipairs(RefineList) do
  25.             AddItemToDeconstructMessage(thing.bagId, thing.slotIndex, thing.quantity)
  26.             table.remove(RefineList, index)
  27.         end
  28.         SendDeconstructMessage()
  29.         createList()
  30.         d(#RefineList)
  31.     --end
  32. end

sirinsidiator 10/26/19 05:36 AM

It's not possible to tell what is going wrong with only the piece of code you are showing us. It doesn't even include how you define the RefineList. If you want help, upload the whole addon somewhere so I can take a look. ;)

MethosFrost 10/26/19 06:00 AM

Uploaded to ESOUI downloads/info2488-AllCraft.html I appreciate any eyes and input.

Baertram 10/26/19 07:21 AM

Check the code of DoItAll maybe. It builds a slot class which gets the inventory list slot to extract/refine and then adds it to the extraction slot.
There were some problems I had to track down as well like endless loops as slots were not added to a list as they could not be extracted (less than 10 items, or protected by FCOItemSaver e. G.). The list tried to add this item again and again as it stayed inside the normal inventory list for "extraction". So I had to add an "already tried to add to extract" list for it, in order to skip those already tried ones. This fixed the endless loops.

sirinsidiator 10/26/19 07:56 AM

Baertram is right. You never check if the items are actually refined successfully, so you keep readding the same items again and again without ever exiting your while loop.

MethosFrost 10/26/19 03:11 PM

Are you... I feel like an idiot, all I had to do was add little if then before rerolling?

Lua Code:
  1. if SendDeconstructMessage() then
  2.      createList()
  3. end

That fixes the bomb, now I just need to have a way to tell when refine is complete instead.

Thanks for all the assistance

Baertram 10/27/19 05:32 AM

Refine complete = Use event_craft_started -> check if in refine mode (API functiosn exists somewhere in esoui/ingame/crafting) -> event_craft_complete it's done or event_craft_failed / event_craft_aborted it was not finished correctly

Works for all other craftings as well.

Helpfull functions in here:

There exists the function ZO_SmithingExtractionSlot:IsInRefineMode()
ZO_SmithingExtractionSlot should relate to the global variable SMITHING.refinementPanel

I'm using it like this within DoItAll:
Lua Code:
  1. function DoItAll.IsShowingExtraction()
  2.     return not ZO_EnchantingTopLevelExtractionSlotContainer:IsHidden()
  3. end
  5. function DoItAll.IsShowingDeconstruction()
  6.     return not ZO_SmithingTopLevelDeconstructionPanelSlotContainer:IsHidden()
  7. end
  9. function DoItAll.IsShowingRefinement()
  10.     return not ZO_SmithingTopLevelRefinementPanelSlotContainer:IsHidden()
  11. end
  13. local function GetExtractionContainerFunctionCtrlAndPanel()
  14.   if DoItAll.IsShowingExtraction() then
  15.     return ZO_EnchantingTopLevelInventoryBackpack, ExtractEnchantingItem, ENCHANTING, ENCHANTING
  16.   elseif DoItAll.IsShowingDeconstruction() then
  17.     return ZO_SmithingTopLevelDeconstructionPanelInventoryBackpack, ExtractOrRefineSmithingItem, SMITHING, SMITHING.deconstructionPanel
  18.   elseif DoItAll.IsShowingRefinement() then
  19.     return ZO_SmithingTopLevelRefinementPanelInventoryBackpack, ExtractOrRefineSmithingItem, SMITHING, SMITHING.refinementPanel
  20.   end
  21. end

And for the extraction then:
Lua Code:
  1. container, extractFunction, craftingTableCtrlVar, craftingTablePanel = GetExtractionContainerFunctionCtrlAndPanel()

Lua Code:
  1. if craftingTableCtrlVar.CanItemBeAddedToCraft then
  2.             extractable = craftingTableCtrlVar:CanItemBeAddedToCraft(slot.bagId, slot.slotIndex)
  3.             --Refinemant only if stackcount >= 10
  4.             if DoItAll.IsShowingRefinement() and doitall_slot.stackCount ~= nil and doitall_slot.stackCount < 10 then
  5.                 extractable = false
  6.             end
  7.             --Some more checks like the maximum multicraft items (ZOs added a maximum constant MAX_ITERATIONS_PER_DECONSTRUCTION here -> See file DoItAll/src/ExtractAll/Extraction.lua)
  8.            --Check if the items to add to the extract slot are >= MAX_ITERATIONS_PER_DECONSTRUCTION (for refine it needs to be multiplied by the stackCount as each item of the 10 to refine counts as a single one!!!) and if it's => above the constant MAX_ITERATIONS_PER_DECONSTRUCTION extract those first (there cannot be added more then!) and return with the next "batch" of items to extract.
  9.             ...
  10.             if extracable then
  11.               craftingTableCtrlVar:AddItemToCraft(slot.bagId, slot.slotIndex))
  12.            endif

And at the end check if only 1 or multiple items are added to the slot and extract them:
Lua Code:
  1. if extractionSlot:HasOneItem() and craftingTablePanel.ExtractSingle then
  2.    craftingTablePanel:ExtractSingle()
  3. elseif extractionSlot:HasMultipleItems() then
  4.  if showConfirmatioNDialog then
  5.     craftingTablePanel:ConfirmExtractAll()
  6.  else
  7.  --Attention: Direct extraction, no confirmation dialog!
  8.    craftingTablePanel:ExtractAll()
  9. end
  11. end

I'm registering a callback function at EVENT_CRAFT_STARTED for EVENT_CRAFT_COMPLETE and EVENT_CRAFT_FALIED. If one of them gets called it will be unregistering the 2 callback functions again. Same if next EVENT_CRAFT_STARTED is called.

Hope this helps.

All times are GMT -6. The time now is 07:59 AM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2014 - 2019 MMOUI