0

I'm developing a player price tracking function that returns 50 results per request, and I'm sending 8 requests - so I'll be getting 400 results back.

I want to have all 400 results in a multi-dimensional array (as I want to have one element that stores the player's rating and another that will store the price) and have the functionality up to a point.

// DEFAULT VARIABLES
Variables.binArray = arrayNew(1);
Variables.startPosition = 0;

// LOOP 8x50 TIMES = 400 CARDS
for (i=1; i <= 8; i++) {
    // DO SEARCH
    Variables.searchPlayer = Application.cfcs.Search.doPlayerSearch(URL.assetID,0,"",0,0,0,0,Variables.startPosition,ListLast(Session.pricingAccountPhishingKey,"="),Session.pricingAccountSessionKey);
    if (Variables.searchPlayer.StatusCode EQ "200 OK") {
        Variables.searchResults = DeserializeJSON(Variables.searchPlayer.FileContent);
        Variables.numResults = arrayLen(Variables.searchResults.auctionInfo);
        // IF MORE THAN ONE RESULT RETURNED
        if (StructKeyExists(Variables,"numResults") AND Variables.numResults GT 0) {
            // LOOP ROUND RESULTS
            for (j=1; j<=Variables.numResults; j++) {
                // SET BIN PRICE FROM LOWEST CARD
                if (Variables.searchResults.auctionInfo[i].itemData.assetID EQ URL.assetID AND Variables.searchResults.auctionInfo[i].buyNowPrice GT 0 AND Variables.searchResults.auctionInfo[i].sellerName NEQ "Mendoza Juniors") {
                    binArray[j] = arrayNew(1);
                    binArray[j][1] = Variables.searchResults.auctionInfo[j].itemData.rating;
                    binArray[j][2] = Variables.searchResults.auctionInfo[j].buyNowPrice;
                }
            }
        }
    }
    // INCREASE START POSITION
    Variables.startPosition = Variables.startPosition + 50;
}

As you can see I have an initial loop that will send the 8 requests and within each iteration I have another loop that loops round all returned results and adds them to the array.

My problem is that I am only getting the last 50 results returned in my array rather than the 400.

How do I amend my code so that all 400 results are stored in the one array?

2 Answers 2

1

You're overwriting binArray on each j loop, so binArray[j] is always going to be 1 on it's first loop pass even when the i loop is greater then 1. You need to find the array length first.

So try changing this:

binArray[j] = arrayNew(1);
binArray[j][1] = Variables.searchResults.auctionInfo[j].itemData.rating;
binArray[j][2] = Variables.searchResults.auctionInfo[j].buyNowPrice;

to this:

jj = ArrayLen(binArray)+1;
binArray[jj] = arrayNew(1);
binArray[jj][1] = Variables.searchResults.auctionInfo[j].itemData.rating;
binArray[jj][2] = Variables.searchResults.auctionInfo[j].buyNowPrice;
Sign up to request clarification or add additional context in comments.

Comments

0

You should treat binArray as a 3D array.

if (Variables.searchResults.auctionInfo[i].itemData.assetID EQ URL.assetID AND Variables.searchResults.auctionInfo[i].buyNowPrice GT 0 AND Variables.searchResults.auctionInfo[i].sellerName NEQ "Mendoza Juniors") {
      binArray[i][j] = arrayNew(1);
      binArray[i][j][1] = Variables.searchResults.auctionInfo[j].itemData.rating;
      binArray[i][j][2] = Variables.searchResults.auctionInfo[j].buyNowPrice;
}

This should create an array that ends up like this:

[1..8][1..50][1..2]

8 Comments

Will this not create 8 arrays?
no, it updates only 1 array. As it is, you currently re-create binArray 8 times
TBH, I question whether a multi-dimensional array is the correct data structure to use here. Surely binArray[j] (in the original code) should be a struct keyed on rating and buyNowPrice, not an array indexed on 1 and 2..?
I've actually changed the approach altogether and am now adding the results to a query as I need to get the lowest price for each individual rating so using QoQs allows me to do this
Unless you need data that is not associated with the lowest priced item, maybe you should change your approach event more so that you don't waste resources on stuff you don't need.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.