我正在设置可以进行价格检查的TF2交易机器人。定义布尔值是否以键定价时,我得到一个错误。
我尝试将isKeys替换为data [baseName] .prices [qualityId.toString()]。Tradable [craftable [isCraftable.toString()] [0] .currency ==“ keys” in if语句,但得到if语句中的右括号错误。
var data = {
};
var currencies = {
};
requestify.get('https://backpack.tf/api/IGetPrices/v4?raw=1&since=0&key=5cf17c256780725011449df2')
.then(function(response) {
data = response.getBody().response.items;
console.log(data["Australium Tomislav"].prices["11"].Tradable.Craftable);
}
);
requestify.get('https://backpack.tf/api/IGetCurrencies/v1?key=5cf17c256780725011449df2')
.then(function(response) {
currencies = response.getBody().response.currencies;
}
);
function toRef(keys, high) {
if (high) {
if (currencies.keys.price.value_high != undefined){
return currencies.keys.price.value_high * keys
} else {
return currencies.keys.price.value * keys
}
} else {
return currencies.keys.price.value * keys
}
}
function getPrice(item, high) {
var name = item.market_name;
var quality = item.tags[0].name;
var baseName = name.replace(quality + " ", "");
var qualityId = itemQualities[quality];
var isCraftable = true;
var isKeys = data[baseName].prices[qualityId.toString()].Tradable[craftable[isCraftable.toString()][0].currency == "keys"; // Error here
for (i = 0;i < item.description.length;i++) {
if (item.description[i].value == '( Not Usable in Crafting )') {
isCraftable = false;
}
}
if (high) {
if (isKeys) {
return toRef(data[baseName].prices[qualityId.toString()].Tradable[isCraftable.toString()][0].value_high], true);
} else {
return data[baseName].prices[qualityId.toString()].Tradable[isCraftable.toString()][0].value_high];
}
} else {
if (isKeys) {
return toRef(data[baseName].prices[qualityId.toString()].Tradable[isCraftable.toString()][0].value], false);
} else {
return data[baseName].prices[qualityId.toString()].Tradable[isCraftable.toString()][0].value];
}
}
}
`
G:\ BOT \ bot.js:106 var isKeys = data [baseName] .prices [qualityId.toString()]。Tradable [craftable [isCraftable.toString()] [0] .currency ==“ keys”; ^
SyntaxError:意外令牌;
是我得到的错误
答案 0 :(得分:2)
TL; DR :您在错误的行上缺少]
。并且在]
行的下面还有多余的if(high){...}
。
您在行中缺少方括号]
,
var isKeys = ...
如其他答案所示。
现在,我们不知道数据结构,
data[baseName]
.prices[qualityId.toString()]
.Tradable[craftable[isCraftable.toString()][0].currency*]*
或
data[baseName]
.prices[qualityId.toString()]
.Tradable[craftable[isCraftable.toString()][0]*]*.currency
但是,
您在行上有多余的方括号,
if (high) {
if (isKeys) {
/*--here>>*/return toRef(data[baseName].prices[qualityId.toString()].Tradable[isCraftable.toString()][0].value_high, true);
} else {
/*--here>>*/return data[baseName].prices[qualityId.toString()].Tradable[isCraftable.toString()][0].value_high;
}
} else {
if (isKeys) {
/*--here>>*/ return toRef(data[baseName].prices[qualityId.toString()].Tradable[isCraftable.toString()][0].value, false);
} else {
/*--here>>*/return data[baseName].prices[qualityId.toString()].Tradable[isCraftable.toString()][0].value;
}
}
同样,我们不知道确切的数据结构。
答案 1 :(得分:1)
您缺少可交易的方括号
([\D\s]+)(\d+)([\D\s]+)
答案 2 :(得分:1)
在该行中缺少方括号(dX
)。
您的行是:
#include <cmath>
#include <iostream>
#include <limits>
#include <type_traits>
struct pos_inf {
constexpr operator double() const { return std::numeric_limits<double>::infinity(); }
};
struct neg_inf {
constexpr operator double() const { return -std::numeric_limits<double>::infinity(); }
};
template<typename dX, typename upper_bound = dX, typename lower_bound = dX>
class limit {
dX dx;
upper_bound lowerBound;
lower_bound upperBound;
double step_size;
public:
limit(dX x, upper_bound lower, lower_bound upper, double step = 1) :
dx{ x }, lowerBound{ lower }, upperBound{ upper }, step_size{ step }
{}
// with infinity these two will invoke operator double(), with actual double it will return the fixed value
dX lower() const { return lowerBound; }
dX upper() const { return upperBound; }
dX value() const { return dx; }
double step() const { return step_size; }
};
int main() {
limit<double, pos_inf, neg_inf> l(3.4, pos_inf(), neg_inf(), 2.2); // infinity
limit<double> l2(3.4, 1, 5, 2.2); // fixed values
std::cout << "value dx = " << l.value() << '\n'
<< "lower lim = " << l.lower() << '\n'
<< "upper lim = " << l.upper() << '\n'
<< "step_size = " << l.step() << '\n';
return EXIT_SUCCESS;
}
您在;(function($){
$(document).scroll(function(){
if ($(this).scrollTop() > 50) {
$('.navbar').removeClass('navbar-dark');
$('.navbar').addClass('navbar-light');
$('.navbar').removeClass('bg-transparent');
$('.navbar').addClass('bg-white');
$('.site-title').addClass('text-dark');
$('.navbar .cta.btn-outline-success').addClass('text-dark');
$('.navbar').addClass('border-bottom');
} else {
$('.navbar').removeClass('navbar-light');
$('.navbar').addClass('navbar-dark');
$('.navbar').removeClass('bg-white');
$('.navbar').addClass('bg-transparent');
$('.site-title').removeClass('text-dark');
$('.navbar .cta.btn-outline-success').removeClass('text-dark');
$('.navbar').removeClass('border-bottom');
}
});
})(jQuery);
处打开了一个方括号,但直到该行末尾才将其关闭。
编译器期望一个]
,但是找到一个var isKeys = data[baseName].prices[qualityId.toString()].Tradable[craftable[isCraftable.toString()][0].currency == "keys"; // Error here
。
我不熟悉您使用的API,但我想以下可以解决该错误:
.Tradable[