Page 1 of 2 12 LastLast
Results 1 to 25 of 28

Thread: Restarting your main loop.

  1. #1
    Join Date
    Jan 2007
    Posts
    513
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Restarting your main loop.

    Hi.

    My question is: How do i restart my mainloop?

    I need this for my script; when it finds out that the character is logged out, it will login the next character, but it needs to start at the begin of the mainloop.

    I was thinking of making a procedure of the mainloop, and then restarting that procedure everytime its needed. But the problem for that is -> The procedure needs to be at the end of all procedures because it needs to know the other procedures.
    But if its at the end of all procedures, then i can't put it in one of my procedures for checking if a player is logged out, because the mainloop-procedure is at the end of the script.. =/

    I hope you understand my problem, and I hope even more that you find a solution


    Thanks for your time!

    EDIT: I released my script here!!
    Srl simply rocks.

  2. #2
    Join Date
    Apr 2007
    Posts
    581
    Mentioned
    1 Post(s)
    Quoted
    2 Post(s)

    Default

    Why not just use repeat?

    SCAR Code:
    program ScarTest;

    begin//mainloop
    repeat
    Writeln('This would repeat these line until you stop the script.');
    wait(100);
    until(false);
    end.


    Or if you want to do a part at the beginning of the mainloop, just make that part a procedure and whenever you need it, call the procedure.

  3. #3
    Join Date
    Jun 2006
    Location
    USA
    Posts
    1,828
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    GetApplication.RUN will run the whole script again.
    Works in SCAR 2.03 and SCAR 3.04 I think.
    Doesn't work in SCAR 3.00...

  4. #4
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    Or you can use Labels (I think).

    Something like

    SCAR Code:
    if not LoggedIn then
      begin
        WriteLn('Oh dear, we are logged out.');
        NextPlayer(False);
        Goto BeginOfMainLoop //Set BeginOfMainLoop as a label at the start of you mainloop
      end
    Hup Holland Hup!

  5. #5
    Join Date
    Jan 2007
    Posts
    513
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by nielsie95 View Post
    Or you can use Labels (I think).

    Something like

    SCAR Code:
    if not LoggedIn then
      begin
        WriteLn('Oh dear, we are logged out.');
        NextPlayer(False);
        Goto BeginOfMainLoop //Set BeginOfMainLoop as a label at the start of you mainloop
      end
    Does That Exists? I can't find it in the SCAR manual, neither in the SRL manual...


    Quote Originally Posted by penti
    GetApplication.RUN will run the whole script again.
    Works in SCAR 2.03 and SCAR 3.04 I think.
    Doesn't work in SCAR 3.00...
    Then how would i use it in my procedure?

    @ShawnjohnSJ -> I am checking if the player is logged in every procedure.. So it would break out of the loop if you 're repeating..
    Srl simply rocks.

  6. #6
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    Quote Originally Posted by Rambozin View Post
    Does That Exists? I can't find it in the SCAR manual, neither in the SRL manual...
    http://www.srl-forums.com/forum/poin...ghlight=labels
    Hup Holland Hup!

  7. #7
    Join Date
    Mar 2007
    Posts
    674
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    SCAR Code:
    if not LoggedIn then
      begin
        WriteLn('Oh dear, we are logged out.');
        NextPlayer(False);
        Goto BeginOfMainLoop //Set BeginOfMainLoop as a label at the start of you mainloop
      end

    Can there be something like
    SCAR Code:
    Goto Setplayer
    where "setplayer" is one of my procedures?

  8. #8
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    Not really.. Check out the link I posted above you
    Hup Holland Hup!

  9. #9
    Join Date
    Jan 2007
    Posts
    513
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Rambozin, you do not have permission to access this page. This could be due to one of several reasons:

    1. Your user account may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
    2. If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.
    What now? =/
    Srl simply rocks.

  10. #10
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    I'm sorry it's members .

    But here's what it basicly is:

    SCAR Code:
    program lblTest;

    label
      lblBack; //Set your label as a variable here

    var
      Count: Integer;

    begin
    lblBack: //This is your label
      WriteLn('Hello');
      Count := Count + 1;
      if Count < 5 then goto lblBack; //It will keep going back to lblBack until Count is 5+.
    end.
    Hup Holland Hup!

  11. #11
    Join Date
    Feb 2007
    Location
    Het ademt zwaar en moedeloos vannacht.
    Posts
    7,211
    Mentioned
    26 Post(s)
    Quoted
    72 Post(s)

    Default

    Put on top on your procedures if not loggedin then exit;
    This will skip the procedure when the character is not loggedin, thus effectively skipping everything of your main loop, and restarting it when a character is logged in.
    I made a new script, check it out!.

  12. #12
    Join Date
    Jan 2007
    Posts
    513
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by nielsie95 View Post
    I'm sorry it's members .

    But here's what it basicly is:

    SCAR Code:
    program lblTest;

    label
      lblBack; //Set your label as a variable here

    var
      Count: Integer;

    begin
    lblBack: //This is your label
      WriteLn('Hello');
      Count := Count + 1;
      if Count < 5 then goto lblBack; //It will keep going back to lblBack until Count is 5+.
    end.
    Hmm.. So if I would use it in my script it would be something like
    SCAR Code:
    procedure RestartMainLoop;
    begin
      label
        lblBack;  ---I dont really understand this.. ?---
      lblBack: --huh?--
         goto lblBack;
    end;

    procedure BlahBlah
    begin
      If (not (LoggedIn) then
      NextPlayer(True);
      RestartMainLoop;
      .... // rest of procedure
    end;

    --main loop--
    begin
      SetupSRL
      ...
      lblBack;
      ...
    end.
    Srl simply rocks.

  13. #13
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    SCAR Code:
    program lblTest;
     
    label
      lblMainLoop; //Set this just as you would set x, y (but now it's not a var but a label)
     
    var
      tx, ty: Integer; //Your other variables (Integers for mousemovements)

    procedure LoginPlayer;
    begin
      Blabla;
      LogInPlayer;
    end;

    Procedure WalkToA;
    begin
      walk
      walk
      walk
    end;

     
    begin
      SetupSRL;
      ActivateClient;
    {*} lblMainLoop; //You set the label JUST BY WRITING IT SOMEWHERE =]

      repeat
       LoginPlayer;
       WalkToA;
       if not LoggedIn then goto lblMainLoop //goto lblMainLoop makes it go back to where you set the label, so the means we are at the *
      until False
    end.

    Hopes this explains it abit
    Hup Holland Hup!

  14. #14
    Join Date
    Jan 2007
    Posts
    513
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Yea now i understand it! Rep+ for you!

    Another question, a bit offtopic.. could you answer?

    In my script, i have something like this:
    SCAR Code:
    if (IsUpText('...')) then
    begin
      Result := True;
    end else
    begin
      Result := False;
    end;

    Now, i am looking for something that would make sure that i wont log out, but the mouse needs to stay at the same point. Rotating the screen isn't an option because the object is very small. Do you have any ideas?
    Srl simply rocks.

  15. #15
    Join Date
    Mar 2007
    Posts
    674
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    This stuff is confusing...

  16. #16
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    @Rambozin: Not really, try to get the Coords of the mouse and try to move the move to exactly the same spot everytime. Like this:

    SCAR Code:
    function ThingPresent: Boolean;
    var tx, ty: integer;
    begin
      GetMousePos(tx, ty); //Gets the mouse position
      Antiban;  //Does antiban and makes sure you don't logout.
      MMouse(tx, ty, 0, 0); //Moves the move to exact the same position as where it came from
      wait(50);
      Result := IsUpText('..'); //Does what your procedures does, only shorter
    end;
    Hup Holland Hup!

  17. #17
    Join Date
    Jan 2007
    Posts
    513
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Oh yea, Thanks!
    But then i will make a special antiBan for that part of my script, because when it rotates the screen, then my object will be moved ..

    A Big Thanks
    Srl simply rocks.

  18. #18
    Join Date
    Jan 2007
    Posts
    513
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Question about the labels:
    Does "if not LoggedIn then goto lblRestartMainLoop" needs to ne in the mainloop?

    because.. when i compile it says
    Line 1649: [Error] (20083:6): Unknown identifier 'lblRestartMainLoop' in script
    SCAR Code:
    if (not (LoggedIn)) then
      begin
        RandomNextPlayer(True);
        goto lblRestartMainLoop;    ---- on this line
      end;
    (this is a part of the procedure)
    Srl simply rocks.

  19. #19
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    Not sure, did you set lblRestartMainLoop?

    Another thing you could use is:

    SCAR Code:
    begin
      SetupSRL;
      LoginPlayer;
       repeat //Repeats your mainloop
        repeat
         //MainLoop
         WalkToA;
         DoAThing;
        until not LoggedIn //Repeats the mainloop until you are not loggedin
        RandomNextPlayer(True)  //when you are not loggedin, it will login a random next player and start the mainloop again
       until False
    end.
    Hup Holland Hup!

  20. #20
    Join Date
    Jan 2007
    Posts
    513
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Well, How do i set it? ..

    I am not only using the label for loggin in, I also need one for in a procedure..
    Srl simply rocks.

  21. #21
    Join Date
    Jan 2007
    Posts
    513
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Hmm, i really dont understand how to use labels =/

    I have it like this:

    Program Example;

    var
    [variables here]

    label
    lblMyLabel;

    procedure MyProcedure;
    begin
    if (not (LoggedIn)) then
    Exit;
    x := mscx;
    y := mscy;
    lblMyLabel:
    MakeCompass('W');
    HighestAngle;
    ... // more of the procedure
    if (CheckSpot = False) then
    goto lblMyLabel;
    end;

    begin // main loop
    SetupSRL;
    ... // more of my main loop
    MyProcedure;
    ... // more of my main loop
    end. // end of main loop
    what am i doing wrong?
    Srl simply rocks.

  22. #22
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    You set it by just writing it somewhere. And I'm not sure if you can use it in a procedure, maybe it's mainloop only. But take a look at the post above you, that's a whole lot easier.

    It should work what you've now. What error do you get?

    EDIT: Yes, I don't think you can use labels in procedures. But what you can do is call the procedure out of the procedure:

    SCAR Code:
    program lblTest;

    label
      lblBack; //Set your label as a variable here

    var
      Count, i: Integer;

    procedure hello;
    begin
      Writeln('Helllo Hello');
      i := i +1;
      if i < 5 then Hello;   //It will keep repeating this procedure until i is 5+
    end;

    begin
    lblBack: //This is your label
      WriteLn('Hello');
      Count := Count + 1;
      if Count < 5 then goto lblback; //It will keep going back to lblBack until Count is 5+.
      Hello;
    end.

    So in your case it would be:

    SCAR Code:
    procedure MyProcedure;
    begin
    if (not (LoggedIn)) then
    Exit;
    x := mscx;
    y := mscy;
    lblMyLabel:
    MakeCompass('W');
    HighestAngle;
    ... // more of the procedure
    if (CheckSpot = False) then MyProcedure
    end;
    Hup Holland Hup!

  23. #23
    Join Date
    Jan 2007
    Posts
    513
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Unknown identifier 'lblMyLabel'
    right here:

    ...
    y := mscy;
    lblMyLabel: --- here
    MakeCompass('W');
    ...
    Srl simply rocks.

  24. #24
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    I know, did you read the post above you?
    I edited it..
    Hup Holland Hup!

  25. #25
    Join Date
    Jan 2007
    Posts
    513
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    So .. I don't need a label in that procedure?

    Tough, I like to know how to use labels for in the futher
    Srl simply rocks.

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Main loop???
    By cloutier15 in forum OSR Help
    Replies: 3
    Last Post: 05-11-2008, 09:53 PM
  2. Main Loop Problem
    By kryptonite in forum OSR Help
    Replies: 9
    Last Post: 07-25-2007, 02:22 PM
  3. Main Loop Issue
    By lefamaster in forum OSR Help
    Replies: 5
    Last Post: 03-22-2007, 09:11 PM
  4. main loop
    By syberium in forum OSR Help
    Replies: 5
    Last Post: 01-23-2007, 07:00 AM

Posting Permissions

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