Results 1 to 8 of 8

Thread: Few questions on certain functions

  1. #1
    Join Date
    Jun 2012
    Posts
    66
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default Few questions on certain functions

    Ok, I am making a bot for a game, I have everything made but I want to add a couple failsafes if possible.

    Is there a way to make a script restart the mainloop if its stuck for more than say like 30 seconds.

    Basically I have it click the button to change worlds untill it sees a DTM matching the world I need to be in. sometimes it gets stuck on this and it shouldnt take more than like 15 seconds to find the world. Can I make it where if the script is stuck in any loop for more than XX seconds it restarts script.

    also I have it repeat mainloop until F3 is pressed. However when F3 is pressed it finishes the whole mainloop before stopping, is there anyway to make it stop as soon as you press f3 no matter where the script is at in the coding?

    Heres my repeat until loop
    Code:
    Begin
    time:=GetSystemTime;
    StartWorld;
    ClickCity;
    Repeat
    MainLoop;
    if(GetSystemTime-time>28800000) then  //8 hrs
    StartWorld;
    ClickCity;
    until (IsKeyDown(114));
    End.

  2. #2
    Join Date
    Jun 2012
    Posts
    4,867
    Mentioned
    74 Post(s)
    Quoted
    1663 Post(s)

    Default

    Quote Originally Posted by cynicz View Post
    Ok, I am making a bot for a game, I have everything made but I want to add a couple failsafes if possible.

    Is there a way to make a script restart the mainloop if its stuck for more than say like 30 seconds.

    Basically I have it click the button to change worlds untill it sees a DTM matching the world I need to be in. sometimes it gets stuck on this and it shouldnt take more than like 15 seconds to find the world. Can I make it where if the script is stuck in any loop for more than XX seconds it restarts script.

    also I have it repeat mainloop until F3 is pressed. However when F3 is pressed it finishes the whole mainloop before stopping, is there anyway to make it stop as soon as you press f3 no matter where the script is at in the coding?

    Heres my repeat until loop
    Code:
    Begin
    time:=GetSystemTime;
    StartWorld;
    ClickCity;
    Repeat
    MainLoop;
    if(GetSystemTime-time>28800000) then  //8 hrs
    StartWorld;
    ClickCity;
    until (IsKeyDown(114));
    End.

    Here's an example of how you can do the first thing you want, but you'll probably need to change it to fit your needs.
    Simba Code:
    procedure doStuff;
    var
      t: TTimeMarker;
    begin
      t.start;//starts your t TTimeMarker.
      repeat
        if (t.getTime > (15 * 1000) then  //if time passed since t.start is greater than 15 seconds then...
          break();//breaks out of your current loop.
        stuff;
      until(condition);//put what you want to happen for it to stop here.
    end;

    For the second thing, afaik you can't have it stop it at any time because that would require multi-threading, but you could have it stop at almost any time by adding
    Simba Code:
    if (IsKeyDown(114) then
      break();
    between procedures or even within procedures.

  3. #3
    Join Date
    Jun 2012
    Posts
    66
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    i didnt know about the if keydown then break process thanks much, also how would I use the first part? like where would I call it in at? its not really 1 specific loop im worried about its every procedure, or would I need to place it in every procedure?

    and what exactly does "break" do, like does it just stop the script? how can I make it instead of stopping a script it restarts it.

  4. #4
    Join Date
    Jun 2012
    Posts
    4,867
    Mentioned
    74 Post(s)
    Quoted
    1663 Post(s)

    Default

    Quote Originally Posted by cynicz View Post
    i didnt know about the if keydown then break process thanks much, also how would I use the first part? like where would I call it in at? its not really 1 specific loop im worried about its every procedure, or would I need to place it in every procedure?

    and what exactly does "break" do, like does it just stop the script? how can I make it instead of stopping a script it restarts it.
    "break" breaks out of the loop that you're currently in. So if you had a loop in your mainloop without anything after, breaking out of that would stop your script. If you want to restart the entire script, put everything that you want to restart in a loop and then use "continue" to restart the loop.

    As for the first part, that's just an example of how you can use TTimeMarkers with loops. You can use it in every procedure if you want.g

  5. #5
    Join Date
    Jun 2012
    Posts
    66
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    my Mainloop procedure has all my procedures in a loop then I use the Begin with the End. to repeat Mainloop;

    Code:
    Procedure MainLoop;
    Begin
      GotoFarm;
      Tree;
      CloseFarmShop;
      Plot1;
      CloseFarmShop;
      Plot2;
      CloseFarmShop;
      Plot3;
      CloseFarmShop;
      Plot4;
      CloseFarmShop;
      Plot5;
      CloseFarmShop;
      Plot6;
      CloseFarmShop;
      Plot7;
      CloseFarmShop;
      Plot8;
      CloseFarmShop;
      Plot9;
      CloseFarmShop;
      Contribute;
      GotoTown;
      Progress;
    End;
    
    
    Begin
    time:=GetSystemTime;
    StartWorld;
    ClickCity;
    Repeat
    MainLoop;
    if(GetSystemTime-time>28800000) then  //8 hrs
    StartWorld;
    ClickCity;
    until (IsKeyDown(114));
    End.

    how would I add to every procedure so that if its stuck for more than 30 seconds completely restart the whole script starting at the begining of this code again.

    Code:
    Begin
    time:=GetSystemTime;
    StartWorld;
    ClickCity;
    Repeat
    MainLoop;
    if(GetSystemTime-time>28800000) then  //8 hrs
    StartWorld;
    ClickCity;
    until (IsKeyDown(114));
    End.
    [/CODE]

  6. #6
    Join Date
    Jun 2012
    Posts
    4,867
    Mentioned
    74 Post(s)
    Quoted
    1663 Post(s)

    Default

    Does it get stuck within each procedure?
    If so you'd have to add find out where it gets stuck and use the timeout there.

  7. #7
    Join Date
    Jun 2012
    Posts
    66
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default

    it has a possibility of getting stuck yes. if someone sends a room invite for a raid, during any procedure that screen will pop up for 30 seconds which will throw off every procedure. I tried making a DTM to check for the "reject" button but its always different colors.

    This is why I wanted to find a way to just at ANY time if the bot is stuck for more than 30 seconds then restart script. because no wait is over 30 seconds. i guess I can just run the ttimer with my finddtm sicne if it cant find dtm it will sit in a loophole.

    is there a way I can restart the script then? like if i use your timer method and it hits 30seconds, it breaks and skips to the next procedure which is a failsafe, that checks screen image, if its false it restarts script?

    im hitting an error with the break command.

    Code:
    [Error] C:\Users\***\Desktop\Script.simba(16:3): Not in a loop at line 16
    Compiling failed.
    Also getting a error with the ttimer (sorry im so dumb with this)

    Code:
    Unknown type 'TTimeMarker' at line 368
    Compiling failed.
    Is there a variable i need in the beginging of my script?
    This is my header

    Code:
    program Script;
    {$i srl/srl.simba}
    //F3 stops script
    Var
    Runs, GoldMade, FarmShop, GSeed, KSeed, city, x, y: Integer;
    time, time2: longint;

  8. #8
    Join Date
    Jan 2012
    Location
    127.0.0.1
    Posts
    702
    Mentioned
    11 Post(s)
    Quoted
    76 Post(s)

    Default

    use the "break / continue functions"

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •