seishun / node-steam

Interface directly with Steam servers from Node.js
MIT License
1k stars 180 forks source link

TypeError: Cannot read property '0' of undefined #265

Closed Vynergy closed 8 years ago

Vynergy commented 8 years ago

I need help with this error

C:\Users\Administrator\Desktop\Bot>node tradebot.js socket timed out socket closed connecting to ~****~ connected encrypt request handshake complete Logged in! C:\Users\Administrator\Desktop\Bot\tradebot.js:336 if(offer.items_to_receiv e.length > row[0].value) {

          ^

TypeError: Cannot read property '0' of undefined at Query._callback (C:\Users\Administrator\Desktop\Bot\tradebot.js:336:46) at Query.Sequence.end (C:\Users\Administrator\Desktop\Bot\node_modules\mysql \lib\protocol\sequences\Sequence.js:96:24) at Protocol._validateEnqueue (C:\Users\Administrator\Desktop\Bot\node_module s\mysql\lib\protocol\Protocol.js:218:6) at Protocol._enqueue (C:\Users\Administrator\Desktop\Bot\node_modules\mysql\ lib\protocol\Protocol.js:129:13) at Connection.query (C:\Users\Administrator\Desktop\Bot\node_modules\mysql\l ib\Connection.js:201:25) at C:\Users\Administrator\Desktop\Bot\tradebot.js:335:23 at Array.forEach (native) at C:\Users\Administrator\Desktop\Bot\tradebot.js:329:41 at Object.doAPICall.bind.callback (C:\Users\Administrator\Desktop\Bot\node_m odules\steam-tradeoffers\index.js:284:7) at SteamTradeOffers. (C:\Users\Administrator\Desktop\Bot\node_mod ules\steam-tradeoffers\index.js:256:15)

C:\Users\Administrator\Desktop\Bot>pause Press any key to continue . . . Please help?

jwigley commented 8 years ago

Take a look at line 336 of tradebot.js?

It's pretty hard to debug if you don't post any code.

Vynergy commented 8 years ago

Here is the full code http://pastebin.com/50RBaMWr Here is the 336 line: mysqlConnection.query('SELECT value FROM info WHERE name=\'maxitems\'', function(err, row, fields) { if(offer.items_to_receive.length > row[0].value) { offers.declineOffer({tradeOfferId: offer.tradeofferid}); offer.items_to_receive = []; mysqlConnection.query('INSERT INTO messages (userid,msg,from) VALUES (\''+offer.steamid_other+'\',\'toomuch\',\'System\')', function(err, row, fields) {}); return; }

andrewda commented 8 years ago

This is a MySQL issue, no problem with Node-Steam. You need to check the err variable if you want to fix the issue.

Vynergy commented 8 years ago

https://github.com/seishun/node-steam/issues/265#issuecomment-146726688 I have no idea on what it should be changed to. Someone told me it was that I had the wrong mysql information to connect to db

andrewda commented 8 years ago

@Vynergy Start off by logging the error, and work from there.

Vynergy commented 8 years ago

https://github.com/seishun/node-steam/issues/265#issuecomment-146731965 May I ask how to do this? I am not that good with MySQL. & Sorry for bothering so much :(

andrewda commented 8 years ago

@Vynergy

if (err) {
    throw err;
}

add that to the beginning of the callback for each MySQL statement.

Vynergy commented 8 years ago

https://github.com/seishun/node-steam/issues/265#issuecomment-146733741 Sorry but still confused could you show an example please? like with the codes I put above.

andrewda commented 8 years ago
mysqlConnection.query('SELECT value FROM info WHERE name=\'maxitems\'', function(err, row, fields) {
    if (err) {
        throw err;
    }

    if (offer.items_to_receive.length > row[0].value) {
        offers.declineOffer({tradeOfferId: offer.tradeofferid});
        offer.items_to_receive = [];
        mysqlConnection.query('INSERT INTO messages (userid,msg,from) VALUES (\''+offer.steamid_other+'\',\'toomuch\',\'System\')', function(err, row, fields) {
            if (err) {
                throw err;
            }
        });
        return;
    }
seishun commented 8 years ago

Please don't discuss MySQL here.

Vynergy commented 8 years ago

https://github.com/seishun/node-steam/issues/265#issuecomment-146808015 Where could I post this?

andrewda commented 8 years ago

@Vynergy you're using the stolen CSGOFast code. Try to understand the code (and how to log your errors) before posting it anywhere else.

Vynergy commented 8 years ago

https://github.com/seishun/node-steam/issues/265#issuecomment-146928107 This is what I got with your code. C:\Users\Administrator\Desktop\Bot>node tradebot.js connecting to ` connected encrypt request handshake complete Logged in! C:\Users\Administrator\Desktop\Bot\tradebot.js:337 throw er r; ^

Error: Cannot enqueue Query after fatal error. at Protocol._validateEnqueue (C:\Users\Administrator\Desktop\Bot\node_module s\mysql\lib\protocol\Protocol.js:193:16) at Protocol._enqueue (C:\Users\Administrator\Desktop\Bot\node_modules\mysql\ lib\protocol\Protocol.js:129:13) at Connection.query (C:\Users\Administrator\Desktop\Bot\node_modules\mysql\l ib\Connection.js:201:25) at C:\Users\Administrator\Desktop\Bot\tradebot.js:335:23 at Array.forEach (native) at C:\Users\Administrator\Desktop\Bot\tradebot.js:329:41 at Object.doAPICall.bind.callback (C:\Users\Administrator\Desktop\Bot\node_m odules\steam-tradeoffers\index.js:284:7) at SteamTradeOffers. (C:\Users\Administrator\Desktop\Bot\node_mod ules\steam-tradeoffers\index.js:256:15) at Request.self.callback (C:\Users\Administrator\Desktop\Bot\node_modules\re quest\request.js:197:22) at emitTwo (events.js:87:13)

C:\Users\Administrator\Desktop\Bot>pause Press any key to continue . . .

seishun commented 8 years ago

This is not a help desk.