我打算使用backpacktf模块,但是我不想工作,只是给了我一个json错误,所以我继续使用这个模块:
https://github.com/KenanY/backpack.tf
但我这样做了,我收到了这个错误
C:\用户\ datpe \桌面\ d \ bot.js:94 theirValue + = data [item] .value; ^
TypeError:无法读取属性' Rainy Day Cosmetic Case'为null 在C:\ Users \ datpe \ Desktop \ d \ bot.js:94:24 在BufferList._callback(C:\ Users \ datpe \ node_modules \ jsonist \ jsonist.js:12:14) 在BufferList.end(C:\ Users \ datpe \ node_modules \ bl \ bl.js:75:10) 在Stream.onend(内部/ streams / legacy.js:44:10) 在emitNone(events.js:110:20) 在Stream.emit(events.js:207:7) 在排水管处(C:\ Users \ datpe \ node_modules \ through \ index.js:33:23) 在Stream.stream.queue.stream.push(C:\ Users \ datpe \ node_modules \ through \ index.js:41:5) 在IncomingMessage。 (C:\ Users \用户datpe \ node_modules \ hyperquest \ index.js:60:48) 在emitNone(events.js:110:20)
我猜它是因为我试图获取无效或不存在的信息?
以下是我使用的代码:
function processOffer(offer){
if (offer.isGlitched() || offer.state === 11) {
console.log('Offer was glitched, declining.');
declineOffer(offer);
//} else if(offer.partner.getSteamID64() == config.ownerID) {
// acceptOffer(offer);
} else {
var ourItems = offer.itemsToGive;
var theirItems= offer.itemsToReceive;
var ourValue = 0;
var theirValue = 0;
for(var i in ourItems) {
var item = ourItems[i].market_name;
b.getPrices(function(error, data) {
if(error){
throw error;
}else {
ourValue += data[item].value;
}
});
}
for(var i in theirItems){
var item = theirItems[i].market_name;
b.getPrices(function(error, data) {
if(error){
throw error;
}else {
theirValue += data[item].value;
}
});
}
}
console.log('Our Value: ' + ourValue);
console.log('Their Value: ' + theirValue);
if (ourValue <= theirValue){
acceptOffer(offer);
} else {
declineOffer(offer);
}
}
答案 0 :(得分:0)
var ourItems = offer.itemsToGive;
var theirItems= offer.itemsToReceive;
var ourValue = 0;
var theirValue = 0;
b.getPrices(function(error, data) {
if(error){
throw error;
}else {
for(var i in ourItems){
let item = i.market_name;
if(data[item] && Object.prototype.hasOwnProperty.call(data[item], 'value')){
ourValue += data[item].value;
}
}
for(var i in theirItems){
let item = i.market_name;
if(data[item] && Object.prototype.hasOwnProperty.call(data[item], 'value')){
theirValue += data[item].value;
}
}
}
});