Thread Tools Display Modes
04/10/14, 07:40 PM   #1
Durstie
Join Date: Apr 2014
Posts: 3
Question Check if Pending Trading House Action

I'm trying to create my first addon to cycle through all trading house pages of all my guilds. My script does this loop adequately enough for a first attempt, except it does it too quickly. It gets to the point that it tries to execute a search while waiting for the previous search to complete and I get the "Another action is in process" or similar error in the top right corner of my screen after the first result is processed.

What I want to know is, is there a way to infinite loop (or pause) until there are no pending trading house actions? I found this global variable on the wiki.esoui.com page, but, being a n00b, I don't understand how I can check/use it to my advantage. I've tried looking at examples of other scripts that use those globals, but their implementations cause mine to freeze. I tried a while do loop where the --COMMENT-- is in my code below, to check if the global was set; but it just caused my game to crash.

GLOBAL - TRADING_HOUSE_RESULT_SEARCH_PENDING

Any suggestions or guidance?

Code:
function THP.getStoreListings(guildId)
  local numPages
  if SelectTradingHouseGuildId(guildId) then
    ClearAllTradingHouseSearchTerms()
    for var=1,100 do
      --If Another Trading House Action Is In Progress Wait for it to complete--
      ExecuteTradingHouseSearch(var, TRADING_HOUSE_SORT_SALE_PRICE, true)
      for index=1,100 do
        local icon, itemName, quality, stackCount, sellerName, timeRemaining, purchasePrice = GetTradingHouseSearchResultItemInfo(index)
        if icon then
          THP.print(stackCount .. "x " .. itemName)
        end
      end
    end
  end
end
Thank you,


Durstie
  Reply With Quote
04/11/14, 02:49 PM   #2
Iyanga
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 183
Originally Posted by Durstie View Post
I'm trying to create my first addon to cycle through all trading house pages of all my guilds. My script does this loop adequately enough for a first attempt, except it does it too quickly. It gets to the point that it tries to execute a search while waiting for the previous search to complete and I get the "Another action is in process" or similar error in the top right corner of my screen after the first result is processed.

What I want to know is, is there a way to infinite loop (or pause) until there are no pending trading house actions? I found this global variable on the wiki.esoui.com page, but, being a n00b, I don't understand how I can check/use it to my advantage.

I suspect it's the return code for the Execution function.

Code:
local result = ExecuteTradingHouseSearch(var, TRADING_HOUSE_SORT_SALE_PRICE, true)
if result == TRADING_HOUSE_RESULT_SEARCH_PENDING then
  d("Whoops, too fast.")
elseif result == TRADING_HOUSE_RESULT_SUCCESS then
  domystuff()
else
  d("Something else failed")
end
Now, delaying is a bit more tricky. You could use an OnUpdate() handler to keep your addon informed about the current time and then process the next search when enough time has passed. You set the event handler when you start a search and remove it again when the search is completed.
  Reply With Quote
04/11/14, 03:21 PM   #3
Xrystal
caritas omnia vincit
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 369
Have a look at the trading house events on the wiki. If it is anything like in WOW one or more of those will be trigger events as to when the data is available after the call to search has been started. The names of some of them sound promising.

So either try registering just before or just after the call to search and use the event function to get the details.
  Reply With Quote
04/11/14, 11:23 PM   #4
Durstie
Join Date: Apr 2014
Posts: 3
Smile Global Variables

So, if the global variables get set during particular events (like a search being sent and waiting for a response), then I should be able to echo the variable value to the chat box to watch its value change in my script as it is running too fast. This should tell me the different states of the variable (nil, 0, 1, true, false, etc.). I wasn't sure if I could check the globals directly since it crashed my game the last time I tried. That might be because I was doing it wrong. Like I said, I've only been at LUA scripting for less than a week now. :$

Thank you Iyanga and Xrystal for the tips. I checked the events, and there is no "Waiting for trading house response" event. I've read over the events and stared at that list for a couple hours while trying to think of a way to code 2 even handlers, one to send the search and one to handle the results; but like I said there is no event triggered when the results are sent back to the client (unless I am misunderstanding).

I'm going back to tinker and think about your suggestions. I'll keep you posted, and thank you for the direction.

Edit 1: I like the idea of setting the result of the search function to a variable and then checking the variable, but according to the wiki that function does not return anything. Not a true, false, integer, etc. Is there an inherent/undocumented return value that is expected that I don't know about?

Edit 2: Xrystal, it appears I was mistaken. I must have been overwhelmed with the amount of data at hand, because I found the search response event, and now have an event handler that echos "Got response" every time a search result is posted! Thanks again, I'm very new to this, but can't believe I overlooked this simple item.... :$ Pressing on!

Thank you,


Durstie

Last edited by Durstie : 04/12/14 at 12:22 AM. Reason: Adding more comments and updates.
  Reply With Quote
04/12/14, 06:26 AM   #5
Iyanga
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 183
Originally Posted by Durstie View Post
So, if the global variables get set during particular events (like a search being sent and waiting for a response), then I should be able to echo the variable value to the chat box to watch its value change in my script as it is running too fast.
It's not a global variable, it's a global constant. And therefore it will always have the same value.

This should tell me the different states of the variable (nil, 0, 1, true, false, etc.). I wasn't sure if I could check the globals directly since it crashed my game the last time I tried.
d(tostring(TRADING_HOUSE_RESULT_SEARCH_PENDING))

should not crash, but as said, the value will be a constant number.
  Reply With Quote
04/12/14, 06:40 AM   #6
Halja
 
Halja's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 111
This sound like a good place to use zo_callLater(function(), ms) as the delay for checking. You could also use an event buffering function to wait. Wykkyd put up a sample of that on the Wiki.
  Reply With Quote
04/12/14, 11:39 AM   #7
Durstie
Join Date: Apr 2014
Posts: 3
Smile oops

LOL Global constant. That explains a few things.

I figured a different way. I created a global table to track current action, previous action, etc. Then i created event managers for trading house status received and trading house search result received. The onstatus event happens after you open the trading house and all guild information is returned. This is where i intialize the global table properties and fire off the Sendsearch function. The send search function checks the status of the global table properties and posts the correct search accordingly then just returns nothing.

The search returned event manager checks the global table properties to see if it is supposed to handle the event. If it is, it cycles through the result, creates another table of items, appends the table to the global trading house table, updates the global action table, then fires off the search function again.

Im at the point now where my addon indexes all items in all guild stores and builds a global table of all items. Now, i just need to decide what i want to do with the data.

Thanks all for the tips and advice. Im sure my code could use some optimizing, but it is working as needed for now.

Posted this from my phone. Sorry for typos and poor grammar.

Thank you,


Durstie
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Check if Pending Trading House Action


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off