SyntaxError: missing ] after element list mimo domknięcia nawiasów

0

Przerobiłem bota do pewnej ruletki. (Jest to legalne na portalu którego używam, nawet właściciel portalu sam napisał jednego bota.)
Oto kod:

// CONFIG
var BetOnBlack = true;    // Stawiaj na czarne
var BetOnRed = true;      // Stawiaj na czerwone
var InitialBetAmount = 1; // Stawka
// ===========================================

function tick()
{
  var currentStatus = getStatus();
  if(currentStatus !== lastStatus && "unknown" !== currentStatus)
  {
    switch(currentStatus)
    {
      case"waiting":
	    PlaceBets();
        break;
      case"rolled":
	    CalculateBets()
    }
    lastStatus = currentStatus,printInfo()
  }
}

function checkBalance()
{
  var SumOfBetAmounts = CurrentBlackBetAmount + CurrentRedBetAmount;
  return getBalance() < SumOfBetAmounts ? (console.warn("BANKRUPT! Not enough balance for next bet, aborting."),clearInterval(refreshIntervalId),!1) : !0
}

function printInfo()
{
  var Info = " \nStatus: " + lastStatus + "\nRolls played: " + currentRollNumber + "\nInitial bet amount: " + InitialBetAmount + "\nCurrent black bet amount: " + CurrentBlackBetAmount + "\nCurrent red bet amount: " + CurrentRedBetAmount + "\nLast color: " + LastRollColor;
  console.log(Info)
}

function CalculateBets()
{
  if (LastRollColor == "red")
  {
    CurrentRedBetAmount = InitialBetAmount;
	CurrentBlackBetAmount = CurrentBlackBetAmount * 2;
  }
  if (LastRollColor == "black")
  {
    CurrentRedBetAmount = CurrentRedBetAmount * 2;
	CurrentBlackBetAmount = InitialBetAmount;
  }
  if (LastRollColor == "green")
  {
    CurrentRedBetAmount = CurrentRedBetAmount * 2;
	CurrentBlackBetAmount = CurrentBlackBetAmount * 2;
  }
  currentRollNumber++
}

function PlaceBets()
{
  if (checkBalance() == true)
  {
    if (BetOnBlack == true)
	{
	  (setBetAmount(CurrentBlackBetAmount),setTimeout(placeBet("black"), 50))
	}
	if (BetOnRed == true)
	{
	  (setBetAmount(CurrentRedBetAmount),setTimeout(placeBet("red"), 50))
	}
  }
}

function setBetAmount(AAmount)
{
  $betAmountInput.val(AAmount);
}

function placeBet(AColor)
{
  if (AColor == "red")
    return $redButton.click()
  if (AColor == "black")
    return $blackButton.click()
}

function getStatus()
{
  var StatusBarText = $statusBar.text();
  if(hasSubString(StatusBarText,"Rolling in"))
    return "waiting";
  if(hasSubString(StatusBarText,"***ROLLING***"))
    return "rolling";
  if(hasSubString(StatusBarText,"rolled"))
  {
    var RoledNumber = parseInt(StatusBarText.split("rolled")[1]);
    return LastRollColor=getColor(RoledNumber),"rolled"
  }return "unknown"
}

function getBalance()
{
  return parseInt($balance.text())
}

function hasSubString(AFullString,APartOfString)
{
  return AFullString.indexOf(APartOfString)>-1
}

function getColor(a)
{
  return 0 == a?"green":a >= 1 && 7 >= a?"red":"black"
}

var CurrentBlackBetAmount = InitialBetAmount,
     CurrentRedBetAmount = InitialBetAmount,
     currentRollNumber = 1,
     LastRollColor,
     lastStatus,
     $balance = $("#balance"),
     $betAmountInput = $("#betAmount"),
     $statusBar = $(".progress #banner"),
     $redButton = $("#panel1-7 .betButton"),
     $blackButton = $("#panel8-14 .betButton"),
     refreshIntervalId = setInterval(tick,500);

I gdy wklejam go w konsole przeglądarki (Firefox 43.0.4) to wyskakuje mi błąd SyntaxError: missing ] after element list mimo, że nawiasów kwadratowych używam tylko w jednym miejscu i są one domknięte.
Błąd ten jednak nie przeszkadza w pracy tego skryptu, wszystko działa jak powinno (a przynajmniej tak mi się wydaje, gdy widzę skutki działania kodu).

Ktoś może mi powiedzieć co jest nie tak ze skryptem?

EDIT:
Do walidacji czy kod jest poprawny składniowo używałem tej strony: http://pl.piliapp.com/javascript-validator/
pierwsza lepsza jaką znalazłem w google.

0

To nie z Twoim kodem jest coś nie tak. Twój kod zapewne powoduje wywołanie jakiegoś kodu już u nich, który jest wadliwy.

0

hmm dziwne bo bot którego przerabiałem bez przeróbek nie wywala tego błędu.
EDIT:
Kod bota "podstawowego":

// CONFIG
var initialBetAmount = 1;
var mode = 'martingale';  // can be 'martingale' or 'anti-martingale' (WAT? https://en.wikipedia.org/wiki/Martingale_(betting_system) )
var betColor = 'red';     // can be 'red' or 'black'

function tick()
{
  var currentStatus = getStatus();
  if(currentStatus !== lastStatus && "unknown" !== currentStatus)
  {
    switch(currentStatus)
    {
      case"waiting":
	    bet();
        break;
      case"rolled":
	    rolled()
    }
    lastStatus=currentStatus,printInfo()
  }
}

function checkBalance()
{
  return getBalance() < currentBetAmount?(console.warn("BANKRUPT! Not enough balance for next bet, aborting."),clearInterval(refreshIntervalId),!1):!0
}

function printInfo()
{
  var a=" \nStatus: "+lastStatus+"\nRolls played: "+currentRollNumber+"\nInitial bet amount: "+initialBetAmount+"\nCurrent bet amount: "+currentBetAmount+"\nLast roll result: "+(null===wonLastRoll()?"-":wonLastRoll()?"won":"lost");console.log(a)
}

function rolled()
{
  return"anti-martingale"===mode?void antiMartingale():(martingale(),void currentRollNumber++)
}

function antiMartingale()
{
  currentBetAmount=wonLastRoll()?2*currentBetAmount:initialBetAmount
}

function martingale()
{
  currentBetAmount=wonLastRoll()?initialBetAmount:2*currentBetAmount
}

function bet()
{
  checkBalance()&&(setBetAmount(currentBetAmount),setTimeout(placeBet,50))
}

function setBetAmount(a)
{
  $betAmountInput.val(a)
}

function placeBet()
{
  return"red"===betColor?($redButton.click(),void(lastBetColor="red")):($blackButton.click(),void(lastBetColor="black"))
}

function getStatus()
{
  var a=$statusBar.text();
  if(hasSubString(a,"Rolling in"))
    return"waiting";
  if(hasSubString(a,"***ROLLING***"))
    return"rolling";
  if(hasSubString(a,"rolled"))
  {
    var b=parseInt(a.split("rolled")[1]);
    return lastRollColor=getColor(b),"rolled"
  }return"unknown"
}

function getBalance()
{
  return parseInt($balance.text())
}

function hasSubString(a,b)
{
  return a.indexOf(b)>-1
}

function getColor(a)
{
  return 0==a?"green":a>=1&&7>=a?"red":"black"
}

function wonLastRoll()
{
  return lastBetColor?lastRollColor===lastBetColor:null
}

var currentBetAmount=initialBetAmount,
    currentRollNumber=1,
    lastStatus,
    lastBetColor,
    lastRollColor,
    $balance=$("#balance"),
    $betAmountInput=$("#betAmount"),
    $statusBar=$(".progress #banner"),
    $redButton=$("#panel1-7 .betButton"),
    $blackButton=$("#panel8-14 .betButton"),
    refreshIntervalId=setInterval(tick,500);
1

lastStatus=currentStatus,printInfo()

Co to za zkładnia z tym przecinkiem? Używaj http://jshint.com/ lub http://www.jslint.com/

1

Z mojegu punktu widzenia to ten kod to straszny syf. Masz tam np. rzeczy typu przekazywanie do setTimeout wartości, podczas gdy setTimeout oczekuje funkcji albo stringa np. setTimeout(placeBet("black"), 1000). To zostaje od razu wywołane i zwraca rezultat funkcji click czyli jQuery collection.

Całkiem możliwe, że to powoduje ten error bo w chromie byś dostał Uncaught SyntaxError: Unexpected identifier. Możesz spróbować tego typu rzeczy owinąć w funkcję:

setTimeout(function() {placeBet("black");}, 1000);

Może to coś da. Tak samo przy interwałach.

0

setTimeout używam tylko w dwóch miejscach i wszędzie jest dobrze.

function PlaceBets()
{
  if (checkBalance() == true)
  {
    if (BetOnBlack == true)
	{
	  (setBetAmount(CurrentBlackBetAmount),setTimeout(placeBet("black"), 50))
	}
	if (BetOnRed == true)
	{
	  (setBetAmount(CurrentRedBetAmount),setTimeout(placeBet("red"), 50))
	}
  }
}
1

To nie jest poprawny zapis bo nie przekazujesz do setTimeout stringa/funkcji. placeBet("black") od razu wywołuje funkcje i nie czeka 50 ms. Ponieważ każda funkcja jQuery zwraca obiet tzn. kolekcję elementów jQuery to suma sumarum do setTimeout trafia Ci OBIEKT, a nie funkcja, bo placeBet("black") wykonuje sie od razu. Sprawdź sobie:

setTimeout(console.log("nie czekam 5 sekund!"), 5000);

setTimeout(function() {console.log("Teraz już czekam");} , 5000);

Poza tym lepiej by było gdybyś zapisał te wywołania po ludzku jedno pod drugim oddzielając średnikami, a nie cudował w ten sposób, bo pierwsze co jak na to spojrzałem to zaczałem się zastanawiać, dlaczego setTimeout przekazywany jako argument.

0
function PlaceBets()
{
  if (checkBalance() == true)
  {
    if (BetOnBlack == true)
	{
	  setBetAmount(CurrentBlackBetAmount);
	  setTimeout(placeBet(), 50, "black");
	}
	if (BetOnRed == true)
	{
	  setBetAmount(CurrentRedBetAmount);
	  setTimeout(placeBet(), 50, "red");
	}
  }
}

O to chodziło? Przerobiłem według tego: http://www.w3schools.com/jsref/met_win_settimeout.asp

EDIT:

function PlaceBets()
{
  if (checkBalance() == true)
  {
    if (BetOnBlack == true)
	{
	  setBetAmount(CurrentBlackBetAmount);
	  setTimeout(function(){ placeBet("black"); }, 50);
	}
	if (BetOnRed == true)
	{
	  setBetAmount(CurrentRedBetAmount);
	  setTimeout(function(){ placeBet("red"); }, 50);
	}
  }
}

Jeśli teraz też będzie źle to się podaję i zostawiam jak jest bo działa i nie mam zamiaru tego udostępniać nigdzie :P

1 użytkowników online, w tym zalogowanych: 0, gości: 1