youssefsoua Posted November 23, 2017 Report Posted November 23, 2017 Hey, I wanted to modify checkAvailableKey() (https://pastebin.com/nYYQGEHE) so when someone write !trade in chat i get this error (https://imgur.com/a/BNbLr) . this is the new code:https://pastebin.com/dE534e9L Thanks in advance !!!<script> </script> Quote
xLeeJYx Posted November 24, 2017 Report Posted November 24, 2017 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; } Quote
TomYoki Posted November 25, 2017 Report Posted November 25, 2017 (edited) 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-callbackExample: 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 November 25, 2017 by TomYoki youssefsoua 1 Quote
Recommended Posts
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.