Results 1 to 9 of 9

Thread: How can I start in the middle of a script?

  1. #1
    Join Date
    Dec 2009
    Posts
    146
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default How can I start in the middle of a script?

    Okay, I'm writing a script, and it is a collection of procedures in a main loop, like most scripts.

    Lets use an example:

    Repeat
    RunToTree;
    ChopTree;
    RunToBank;
    OpenBank;
    DepositLogs;
    CloseBank;
    Until (false);

    So for debugging purposes, how can I jump to a certain part of the script without commenting out some of the procedures?

    Lets say I'm having a problem with OpenBank, I need to jump right to that procedure and start there, without going through all that other stuff first, but once that completes sucessfully I want the script to continue as normal so temporarily commenting out stuff won't work.

  2. #2
    Join Date
    Nov 2009
    Location
    Seattle, WA
    Posts
    589
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Make the Procedures into Functions.
    so like this.
    SCAR Code:
    begin

      repeat

        if (RunToTree) then
         Continue;
        else
          {What to do if it does not Complete the Function};

      until (False); // Use Time Marks for this if you want :P.

    end.

    if thats what you mean, so this way if one Fails [if RunToTree returns False] then it will do w/e you want it to.

    if you wanted to just make the script do a certain procedure by it self = / Besides { }, then open up a new Scar file, copy + Paste the procedure, and try it out in the main loop.
    Last edited by Heavenguard; 01-13-2010 at 09:35 PM.
    Don't Troll, Don't Fight, Just keep the Respect
    Status : Offline

    Feel free to re-make my scripts ;D
    Community Member

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

    Default

    Basically, you want to check for the current "location" of the player. This doesn't necessarily mean physical location, but where along the main loop he is.

    You would know that if your inventory isn't full, you must be chopping trees. Or when your inventory is full (at the trees), you must go to the bank. Of if your inventory is full and is at the bank, then you must be depositing logs. And if your inventory is empty, and you are at the bank, then you have to run to the trees.

    So your code would be something like this:
    SCAR Code:
    if (AtTrees) then
      if InvFull then
        RunToBank;
      else
        ChopTree;
    if (InvFull and AtBank) then
      begin
        OpenBank;
        DepositLogs;
      end;
    if (BankOpen) then
      CloseBank;
    if (InvEmpty and AtBank) then
      RunToTree;

  4. #4
    Join Date
    Nov 2006
    Posts
    235
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Add a call to the procedure before any of the other code.

    i.e. instead of: (I don't know this language, so don't use exact syntax)
    Code:
    Repeat
      //your code
    Until (false);
    use
    Code:
    FunctionYouWishToTest;
    
    Repeat
      //your code
    Until (false);
    If I see you autoing with level 3/default clothes/crap name I WILL report you. Auto Correctly. - put this in your sig
    http://www.stats.srl-forums.com/sigs/5612.png
    http://www.wizards.com/magic/images/...or_iswhite.jpg

  5. #5
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    Check out Labels.
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

  6. #6
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    To explain Nava2's post more:
    SCAR Code:
    label MyLabel;
    begin
       ..
       ..

       ...
       if this = that then
         goto MyLabel;
      ...
      ....
      MyLabel:
     ...
    end;
    That's a brief example on how a label works. if This = That and the script executes the line "goto MyLabel;" then it will skip to the line that say's "MyLabel:". Be careful where you use them though as Labels can not break out of loops.

    Also, I would suggest commenting your code quite frequently if your using labels as they can get confusing to read.

  7. #7
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    Main Loop example (single player, just wrap another loop around for multi)
    Code:
    var errors:integer;
    begin
      SetupScript;
      repeat
    //yea i know, not indented, but it looks neater this way
        if ToTanShop then
        if ToEllis then
        if FindEllis then
        if TanHides then
        if ToBank then
        if FindBankers then
        if MyOpenBank then
        if DepositLeathers then
          errors:=0;
        errors:=errors+1;
        if errors>4 then
          Reset;
      until(Players[CurrentPlayer].Integers[0]<(TannedLeather));
    end.
    Example of a function
    Code:
    function ToEllis:boolean;
    var yellows,yellows3:tpointarray;
    var tmpx,tmpy:integer;
    begin
      if not loggedin then exit;
      writeln('ToEllis-Start');
      if HaveLeathers or TanScreen then
      begin
        writeln('ToEllis-Already done tanning, true')
        result:=true;
        exit;
      end;
      if not FindSymbolIn(tmpx,tmpy,'tanner',mmx1,34,mmx2,mmy2)then
      if not FindSymbolIn(tmpx,tmpy,'furnace',mmx1,53,mmx2,mmy2) then
      begin
        writeln('ToEllis-Cant find tannery or furnace, false');
        result:=false;
        exit;
      end;
      if FindSymbolIn(tmpx,tmpy,'tanner',mmx1,34,mmx2,mmy2)then
      begin
        FindColorsTolerance(yellows,195836,mmx1,mmy1,mmx2,mmy2,0);
        writeln(inttostr(getarraylength(yellows))+' yellow pixels');
        yellows3:=ReArrangeandShortenArrayEx(yellows,4,4);
        writeln(inttostr(getarraylength(yellows3))+' yellow dots');
        SortTPAFrom(yellows3,IntToPoint(tmpx,tmpy));
        setarraylength(yellows3,2);
        SortTPAFrom(yellows3,IntToPoint(mmx2,mmcy));
        Mouse(yellows3[0].x,yellows3[0].y,1,1,true);
        highestangle;
        fflag(0);
      end;
      if HaveLeathers or TanScreen then
      begin
        writeln('ToEllis-Already done tanning, true')
        result:=true;
        exit;
      end;
      result:=true;
    end;
    Which has a bunch of checks to what stage it is at using stuff like this
    Code:
    function HaveLeathers:boolean;
    var tmpx,tmpy:integer;
    begin
      gametab(4);
      if not FindDTM(HideDTM,tmpx,tmpy,mix1,miy1,mix2,miy2) then
        exit;
      if getcolor(tmpx+2,tmpy+4)=getcolor(tmpx+2,tmpy+5) then
        result:=true;
    end;

    This set up was especially useful for me during testing and development, because I was restarting the script after making an edit many times, and this way I didn't have to reset back at the bank every time, it can just pick up at any point.
    Last edited by Boreas; 01-13-2010 at 10:00 PM.

  8. #8
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Labels or step into/over.
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

  9. #9
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    SCAR Code:
    begin
      SetupSRL;
      etc;
      i := 5; // starting position
      repeat
        case i of
          0: Do This;
          1: Do That;
          123: A lot of this;
        end;
        i := (i + 1) mod 124; // replace 124 with the highest case used
        // Randoms or antibans here!
      until (false);
    end.
    Also useful since you can slot in random finding or antiban quite easily and quite nicely if you split up the script nicely.
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

Thread Information

Users Browsing this Thread

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

Tags for this Thread

Posting Permissions

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