Jump to content
McKay Development

Cannot read property 'market_hash_name' of undefined


Recommended Posts

function checkAvailableKey(inventory,acceptedKeyList){
    var i = 0;
    var availableKey = new Array();
    while (i <= inventory.length){
        if (acceptedKeyList.indexOf(inventory[i].market_hash_name) !== -1){
            availableKey.push(i);
            i++;
        }
        else{
            i++;
        }
 
    }
 
    return availableKey;
}

try changing it to this, 

function checkAvailableKey(inventory,acceptedKeyList){
    var i = 0;
    var availableKey = new Array();
    while (i <= inventory.length){
        if (acceptedKeyList.indexOf(inventory[i].market_hash_name) >= 0){
            availableKey.push(i);
            i++;
        }
        else{
            i++;
        }
 
    }
 
    return availableKey;
}
Link to comment
Share on other sites

function checkAvailableKey(inventory,acceptedKeyList){
    var i = 0;
    var availableKey = new Array();
    while (i <= inventory.length){
        if (acceptedKeyList.indexOf(inventory[i].market_hash_name) !== -1){
            availableKey.push(i);
            i++;
        }
        else{
            i++;
        }
 
    }
 
    return availableKey;
}

try changing it to this, 

function checkAvailableKey(inventory,acceptedKeyList){
    var i = 0;
    var availableKey = new Array();
    while (i <= inventory.length){
        if (acceptedKeyList.indexOf(inventory[i].market_hash_name) >= 0){
            availableKey.push(i);
            i++;
        }
        else{
            i++;
        }
 
    }
 
    return availableKey;
}

Honestly, don't comment if you have absolutely no clue what's going on.

 

 

This should work:

 

EDIT: You also have 3 other issues with your code that I did not notice at first (as I didn't look at the main code).

1.) You are using a deprecated method. You want to use https://github.com/DoctorMcKay/node-steam-tradeoffer-manager/wiki/TradeOfferManager#getinventorycontentsappid-contextid-tradableonly-callback

Example: 

manager.getUserInventoryContents(partner, appid, contextid, true, (err, theirInv) => {...});

2.)  Line 158 it needs to be either 'var', 'let' or 'const' unless you are wanting to re-define it.

 

3.)  last issue (that I found) would be on line 163, what you want to do there is change it to 

var keyToAdd = availableKey[0] //Change it simply to 'availableKey' if you want to add all of the keys found.

and from there refer to it as keyToAdd.

 

 

 

Back to your solution for 'checkAvailableKey' function

function checkAvailableKey(inventory, acceptedKeyList){
    var availableKey = []; //Create an empty array where we can store item data.

    for(var i=0; inventory.length>i;i++){ //Loop through inventory.
        if (acceptedKeyList.indexOf(inventory[i].market_hash_name) >= 0){ //Check if there is this item in your array.
            availableKey.push(inventory[i]); //Push all item info, such as assetid, name, amount etc.
        }
    }
 
    return availableKey; //return the array with item data.

    /*
        P.S:
        You don't need to make the function ask for the array every time, just add the array with accepted keys in your global scope.
        However, this is prefered if you have multiple arrays which you want to check.
    */

}
Edited by TomYoki
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...