CPB07
CPB07

Reputation: 699

Multidimensional Array Doing Multiple but needing all items in a single array

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?

Upvotes: 0

Views: 64

Answers (2)

Vernons
Vernons

Reputation: 83

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;

Upvotes: 1

duncan
duncan

Reputation: 31912

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]

Upvotes: 0

Related Questions