Jump to content
McKay Development

offer.itemsToGive/Recieve.length Doesn't Exist


Recommended Posts

function compareItems(offer){
    var myItems=0;
    var yoItems=0;
    //need to get items "specialty" value and multiply by percent
    for (var index = 0; index < offer.itemsToGive.length; ++index) {
        var x= offer.itemsToGive[index].market_hash_name;
        var price=list[x].safe_price;
        console.log(x);
        console.log(price);
        if(price!=0){
            myItems+=price;
            logger.info("Used v2 pricing");
        }
        else{
           // myItems+=list[x].7_days.average_price;
           steamlytics.csgo.prices(x, function(err, data){
               if(err)
                logger.error(err);
                else{
                    myItems+=data.median_price;
                    logger.info("Used regular price function");
                    console.log(data.median_price);
                }
           });
        }
    }
    for (var index = 0; index < offer.itemsToRecieve.length; ++index) {
        var x= offer.itemsToRecieve[index].market_hash_name;
        var price=list[x].safe_price;
        console.log(x);
        console.log(price);
        if(price!=0){
            yoItems+=price;
            logger.info("Used v2 pricing");
        }
        else{
           // myItems+=list[x].7_days.average_price;
           steamlytics.csgo.prices(x, function(err, data){
               if(err)
                logger.error(err);
                else{
                    yoItems+=data.median_price;
                    logger.info("Used regular price function");
                    console.log(data.median_price);
                }
           });
        }
    }
  
    return myItems < yoItems;
}

I tried using the above code to run through an offer and compare the prices of each side. I get an error with the length property of the array itemsToGive/Recieve although in the API it is stated that they are arrays. I received the following error.

 

 

C:\node\fixed.js:335

    for (var index = 0; index < offer.itemsToRecieve.length; ++index) {
                                                    ^
 
TypeError: Cannot read property 'length' of undefined
    at compareItems (C:\node\fixed.js:335:53)
    at manageOffer (C:\node\fixed.js:274:8)
    at TradeOfferManager.<anonymous> (C:\node\fixed.js:192:5)
    at emitOne (events.js:96:13)
    at TradeOfferManager.emit (events.js:188:7)
    at received.forEach (C:\node\node_modules\steam-tradeoffer-manager\lib\polling.js:235:10)
    at Array.forEach (native)
    at getOffers (C:\node\node_modules\steam-tradeoffer-manager\lib\polling.js:219:12)
    at Helpers.checkNeededDescriptions (C:\node\node_modules\steam-tradeoffer-manager\lib\index.js:359:4)
    at Object.exports.checkNeededDescriptions (C:\node\node_modules\steam-tradeoffer-manager\lib\helpers.js:90:3)
    at _apiCall (C:\node\node_modules\steam-tradeoffer-manager\lib\index.js:350:11)
    at SteamCommunity._community.httpRequest (C:\node\node_modules\steam-tradeoffer-manager\lib\webapi.js:54:3)
    at Request._callback (C:\node\node_modules\steamcommunity\components\http.js:67:15)
    at Request.self.callback (C:\node\node_modules\request\request.js:188:22)
    at emitTwo (events.js:106:13)
    at Request.emit (events.js:191:7)
 

I will attempt to do the same thing using a for-of or forEach loop. I will post again shortly with whatever happens.

 

 

Thanks for reading

 

 

EDIT: When I did a for-of loop it didn't give me errors, but nothing ever printed out, meaning the loop never ran. I'll look through the rest of my code to try and find why.

 

This is my code

Edited by African
Link to comment
Share on other sites

  • 2 weeks later...

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...