在Developer's控制台中运行两次Javascript

Running Javascript twice from Developer's console

本文关键字:Javascript 两次 运行 Developer 控制台      更新时间:2023-09-26

我正在玩一个不错的Javascript小游戏Candy Box (http://candies.aniwey.net/),我检查了一下代码。

当我想继续任务时,它发送这个quest.begin(true)。所以我尝试在开发者的控制台中使用它来检查它是否有效。所以我有了另一个想法。这个任务大约需要10秒,所以我将此发送到控制台quest.begin(true);setTimeout(15000);,因为我想创建类似quest.begin(true);setTimeout(15000); * 2的内容。也许你们明白了我想要创建什么。我想自动化做任务,但我不知道如何运行它两次或更多次。我甚至试着这样做:

var questLoop = quest.begin(true) + setTimeout(15000);

,然后运行它questLoop * 2,但它不工作。有谁能告诉我如何运行两次或更多次吗?谢谢你!:)

应该是这样的,尽可能冗长。只要复制粘贴所有内容,它就会运行:

//creating our own scope just in case of collisions
(function(){
  //declare our configuration
  var i = 0;
  var limit = 2;
  //create an interval that runs the code every 15 seconds
  var now = setInterval(function(){
    quest.begin(true);
    //if we reached the limit, stop the interval from running
    if(++i === limit) clearInterval(now);
  },15000);
}());
相关文章: