如何停止IF循环再次运行?在.JS中

时间:2020-07-21 10:45:54

标签: javascript

我正在尝试修改此页面https://mtihc.github.io/bustabit-script-simulator/

上的“ Martingale”脚本

我似乎无法使“ ON LOSS”循环在运行后停止运行。当我第一次下注时,它会首先触发,但第二次下注后,它会再次触发。我可以在脚本中添加什么使其不会连续运行两次的脚本?并给它一个冷却时间。

或者如果我只让“如果下注停止>”重置赔付金额(如果亏损循环连续运行两次)会更容易吗?而不是停止脚本。

这是“ Martingale”的脚本

var config = {
  baseBet: { value: 100, type: 'balance', label: 'base bet' },
  payout: { value: 2, type: 'multiplier' },
  stop: { value: 1e8, type: 'balance', label: 'stop if bet >' },
  loss: {
    value: 'increase', type: 'radio', label: 'On Loss',
    options: {
      base: { type: 'noop', label: 'Return to base bet' },
      increase: { value: 2, type: 'multiplier', label: 'Increase bet by' },
    }
  },
  win: {
    value: 'base', type: 'radio', label: 'On Win',
    options: {
      base: { type: 'noop', label: 'Return to base bet' },
      increase: { value: 2, type: 'multiplier', label: 'Increase bet by' },
    }
  }
};


log('Script is running..');

var currentBet = config.baseBet.value;

// Always try to bet when script is started
engine.bet(roundBit(currentBet), config.payout.value);

engine.on('GAME_STARTING', onGameStarted);
engine.on('GAME_ENDED', onGameEnded);

function onGameStarted() {
  engine.bet(roundBit(currentBet), config.payout.value);
}

function onGameEnded() {
  var lastGame = engine.history.first()

  // If we wagered, it means we played
  if (!lastGame.wager) {
    return;
  }

  // we won..
  if (lastGame.cashedAt) {
    if (config.win.value === 'base') {
      currentBet = config.baseBet.value;
    } else {
      console.assert(config.win.value === 'increase');
      currentBet *= config.win.options.increase.value;
    }
    log('We won, so next bet will be', currentBet/100, 'bits')
  } else {
    // damn, looks like we lost :(
    if (config.loss.value === 'base') {
      currentBet = config.baseBet.value;
    } else {
      console.assert(config.loss.value === 'increase');
      currentBet *= config.loss.options.increase.value;
    }
    log('We lost, so next bet will be', currentBet/100, 'bits')
  }

  if (currentBet > config.stop.value) {
    log('Was about to bet', currentBet, 'which triggers the stop');
    engine.removeListener('GAME_STARTING', onGameStarted);
    engine.removeListener('GAME_ENDED', onGameEnded);
  }
}

function roundBit(bet) {
  return Math.round(bet / 100) * 100;
}

0 个答案:

没有答案
相关问题