Recent Topics

Ads

[Guide] Exploring event results

Here you can post addons, or anything related to addons.
Forum rules
Before posting on this forum, be sure to read the Terms of Use
johndon
Posts: 4

[Guide] Exploring event results

Post#1 » Tue Sep 29, 2020 8:46 pm

Hey all,

I noticed that the WAR API that most point to (located here: https://web.archive.org/web/20090307230 ... ki/WAR_API) does not document what the callback of an event listener receives as arguments. I wanted to share my experience figuring out what was returned when I was listening to the event AUCTION_SEARCH_RESULT_RECEIVED.

Getting started

When you launch RoR and play as a character, you can type /d in the chat box to pull up a debug menu. Click the turn on logs button. Make sure your log isin't filtering out debug statements. (tip: hiding the SoR addon by clicking on the minimap button will stop a good portion of the spam).

Debug logs are kept in <RoR Installation Directory>/logs, so anything we print using d() in an addon or using /script will appear in both the /d window in-game and the .txt file in the logs directory.

RoR's events and listening to them

RoR seems to re-implement the SystemData variable, which all addons should have access to. You can find the old WAR implementation (which seems respected by RoR) here: https://web.archive.org/web/20090302085 ... SystemData

In your addon, register an event handler:

Code: Select all

RegisterEventHandler(SystemData.Events.AUCTION_SEARCH_RESULT_RECEIVED, "Foobar")
The goal now is to figure out 1) how many arguments does the function Foobar receive? and 2) what are the contents of those arguments?

Inspect the arguments to our callback

In lua, you can specify that a function will receive an unspecified amount of arguments placing "..." in lieu of the arguments list. This will provide us with an "args" variable that contains the arguments given to the function.

Code: Select all

RegisterEventHandler(SystemData.Events.AUCTION_SEARCH_RESULT_RECEIVED, "Foobar")

function Foobar(...)
     -- "arg" variable is a table containing the arguments.
end
You can read more about functions with variable number of arguments here: https://www.lua.org/pil/5.2.html

Now, we need to format the args variables in a human readable way. RoR has a built in DUMP_TABLE function that works excellently:

Code: Select all

RegisterEventHandler(SystemData.Events.AUCTION_SEARCH_RESULT_RECEIVED, "Foobar")

function Foobar(...)
     DUMP_TABLE(arg)
end
More info on DUMP_TABLE here: https://web.archive.org/web/20090307232 ... LUA_Tables

If you look open the /d menu in RoR or open the .txt file in your /logs folder, you should see the arguments that were passed to Foobar and their contents. In the case of AUCTION_SEARCH_RESULT_RECEIVED, I see a list of auctions, where each auction looks like this:

Code: Select all

[revision] 1
[itemData]
        [description] 
        [iLevel] 51
 ...
[auctionIDHigherNum] 0
[sellerName] Johndon
[buyOutPrice] 90000
[timeLeft] 3
[auctionIDLowerNum] 4936576
This means I can loop through the one argument containing a list of auctions like so:

Code: Select all

RegisterEventHandler(SystemData.Events.AUCTION_SEARCH_RESULT_RECEIVED, "Foobar")

function Foobar(auctions)
   for _, auction in ipairs(results) do
   	d(auction.buyOutPrice)
   end
end
Be sure to turn off the logging in /d when you're done!

Ads

Who is online

Users browsing this forum: No registered users and 11 guests