Project

General

Profile

 

Also available in: PDF

Iterating Inventory and Handling "iteminfo" Aquisition

The EQ2 client does not store in memory details for every item in your inventory/equipment/bank/etc.  Rather, it waits until you request the information (e.g., when you "examine" an item), then it stores it in a cache for quick access thereafter.   Therefore, ISXEQ2 only has very basic information about all of the inventory/equipment/bank items (the "item" datatype) until the details are requested from the server (which becomes the "iteminfo" datatype.) 

The challenge for scripting is that the request for details from the server does take a couple hundred milliseconds, and ISXEQ2 can't just "sleep" and wait for that data to arrive.  Therefore, when a script needs to access member(s) of the "iteminfo" datatype, it must check to see if it's available and then "wait" until it's cached.

For example:

function main()
{
    variable index:item Items
    variable iterator ItemIterator
    variable int Counter = 1
    
    Me:QueryInventory[Items, Location == "Inventory" && Name =- "Fang"]
    Items:GetIterator[ItemIterator]
 
 
    if ${ItemIterator:First(exists)}
    {
        do
        {
            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
            ;; This routine is echoing the item "Description", so we must ensure that the iteminfo 
            ;; datatype is available.
            if (!${ItemIterator.Value.IsItemInfoAvailable})
            {
                ;; When you check to see if "IsItemInfoAvailable", ISXEQ2 checks to see if it's already
                ;; cached (and immediately returns true if so).  Otherwise, it spawns a new thread 
                ;; to request the details from the server.   
                do
                {
                    waitframe
                    ;; It is OK to use waitframe here because the "IsItemInfoAvailable" will simply return
                    ;; FALSE while the details acquisition thread is still running.   In other words, it 
                    ;; will not spam the server, or anything like that.
                }
                while (!${ItemIterator.Value.IsItemInfoAvailable})
            }
            ;;
            ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
            ;; At this point, the "ToItemInfo" MEMBER of this object will be immediately available.  It should
            ;; remain available until the cache is cleared/reset (which is not very often.)
 
            echo "${Counter}. ${ItemIterator.Value.Name} :: '${ItemIterator.Value.ToItemInfo.Description}'"
            Counter:Inc
        }
        while ${ItemIterator:Next(exists)}
    }
}