2

I am setting up a TF2 trading bot that can price check. I get an error when defining a boolean for if it is priced in keys or not.

I have tried just replacing isKeys with data[baseName].prices[qualityId.toString()].Tradable[craftable[isCraftable.toString()][0].currency == "keys" in the if statement but get an error for the closing bracket in the if statement.

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: Unexpected token ;

is the error I get

Pointy
  • 405,095
  • 59
  • 585
  • 614
row666
  • 47
  • 5

3 Answers3

2

TL;DR: You are missing a ] on the erred line. And you have extra ] on the below if(high){...} lines.

You are missing a square bracket ] in the line, var isKeys = ... as the other answers suggest. Now, we don't know the data structure so it can be,

data[baseName]
    .prices[qualityId.toString()]
    .Tradable[craftable[isCraftable.toString()][0].currency*]*

or

data[baseName]
    .prices[qualityId.toString()]
    .Tradable[craftable[isCraftable.toString()][0]*]*.currency

But Also,

You have extra Square braces on the lines,

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;
        }
    }

Again we don't know the exact data structure.

Aritra Chakraborty
  • 12,123
  • 3
  • 26
  • 35
1

You're missing a square bracket for Tradable

var isKeys = data[baseName].prices[qualityId.toString()].Tradable[craftable[isCraftable.toString()]][0].currency == "keys";
RSchneyer
  • 300
  • 1
  • 8
1

In that line a square-bracket-close (]) is missing.

Your line is:

var isKeys = data[baseName].prices[qualityId.toString()].Tradable[craftable[isCraftable.toString()][0].currency == "keys"; // Error here

You open a bracket at .Tradable[ but it isn't closed until the end of that line. The compiler expects a ] but finds a ;.

I am not familar with the API you are using but I suppose the following would fix the error:

var isKeys = data[baseName].prices[qualityId.toString()].Tradable[craftable[isCraftable.toString()][0].currency == "keys"]; // << Notice the bracket before your semicolon
Sakul6499
  • 29
  • 1
  • 7