Also available in: PDF

Iterating Recipes and Handling "recipeinfo" Aquisition

The EQ2 client does not store in memory details for every recipe in your knowledge book.  Rather, it waits until you request the information (e.g., when you "examine" a recipe), then it stores it in a cache for quick access thereafter.   Therefore, ISXEQ2 only has very basic information about all of your recipes until the details are requested from the server (which becomes the "recipeinfo" 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 "recipeinfo" datatype, it must check to see if it's available and then "wait" until it's cached.

For example:

function main()
    variable index:recipe Recipes
    variable iterator Iterator
    variable int Counter = 1
    variable int Timer = 0
    Me:QueryRecipes[Recipes, Level == 9]
    if ${Iterator:First(exists)}
            ;; This routine is echoing the recipe "Description", so we must ensure that the recipeinfo 
            ;; datatype is available.
            if (!${Iterator.Value.IsRecipeInfoAvailable})
                ;; When you check to see if "IsRecipeInfoAvailable", 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.   
                    ;; It is OK to use waitframe here because the "IsRecipeInfoAvailable" will simple return
                    ;; FALSE while the details acquisition thread is still running.   In other words, it 
                    ;; will not spam the server, or anything like that.
                while (!${Iterator.Value.IsRecipeInfoAvailable} && ${Timer:Inc} < 1500)
            ;; At this point, the "ToRecipeInfo" 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}. ${Iterator.Value.Name} :: '${Iterator.Value.ToRecipeInfo.Description}'"
        while ${Iterator:Next(exists)}
    echo "========"