Results 1 to 18 of 18

Thread: Shorten Code

  1. #1
    Join Date
    Mar 2008
    Location
    Look behind you.
    Posts
    795
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default Shorten Code

    I tried to shorten this code using arrays but massively failed. If anyone can shorten it, i wouldn't mind giving you a rep +.

    SCAR Code:
    procedure CheckShark;
    var
    next, next1, next2, next3: integer;
    start, start1, start2, start3: integer;
    begin
      if InvFull then Exit;
      Respond;
      AntiBan;
      start := InvCount;
      Writeln('Your inv: '+ IntToStr(start));
      RWaitAnti(10000,500);
      AntiBan;
      next := InvCount;
      Writeln('Original inv: '+ IntToStr(start));
      Writeln('New inv: ' + IntToStr(next));
      if InvFull then Exit;
      if start < next then start1 := InvCount;
      if start = next then Exit;
      RWaitAnti(10000,500);
      AntiBan;
      next1 := InvCount;
      Writeln('Original inv: '+ IntToStr(start1));
      Writeln('New inv: ' + IntToStr(next1));
      if InvFull then Exit;
      if start1 < next1 then start2 := InvCount;
      if start1 = next1 then Exit;
      RWaitAnti(10000,500);
      AntiBan;
      next2 := InvCount;
      Writeln('Original inv: '+ IntToStr(start2));
      Writeln('New inv: ' + IntToStr(next2));
      if InvFull then Exit;
      if start2 < next2 then start3 := InvCount;
      if start2 = next2 then Exit;
      RWaitAnti(10000,500);
      AntiBan;
      next3 := InvCount;
      Writeln('Original inv: '+ IntToStr(start3));
      Writeln('New inv: ' + IntToStr(next3));
      if InvFull then Exit;
      if start3 < next3 then RWaitAnti(10000,500);
      if start3 = next3 then Exit;
    end;

    SCAR Code:
    function RWaitAnti(Time,randomtime: integer): integer;
    var
     Time1, Random1, Repeats, Number: integer;
     WriteIt : string;
    begin
      repeat
        if InvFull then Exit;
        Time1 := Time/4;
        Random1 := randomtime/4
        AntiBan;
        Wait(Time1+ random(Random1));
        Repeats := Repeats + 1;
      until(Repeats > 4)
    end;

    It's really long..
    Last edited by DeSnob; 05-14-2009 at 07:04 PM.

  2. #2
    Join Date
    Jul 2007
    Location
    Norway.
    Posts
    1,938
    Mentioned
    3 Post(s)
    Quoted
    0 Post(s)

  3. #3
    Join Date
    Dec 2008
    Location
    In a galaxy far, far away...
    Posts
    584
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    What is the purpose of this procedure... lol like if your only checking for sharks it can be done in like 2 statements....



    ~NS

  4. #4
    Join Date
    Jan 2008
    Location
    Alberta
    Posts
    727
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I think this should work:

    SCAR Code:
    procedure CheckShark;
    var
      i: integer;
      start, next: TIntegerArray;
    begin
      if InvFull or (not LoggedIn) then Exit;
      Respond;
      AntiBan;
      SetArrayLength(Start, 4);
      SetArrayLength(Next, 4);
      for i := 0 to 3 do
      begin
        start[i] := InvCount;
        Writeln('Your inv: '+ IntToStr(start[i]));
        RWaitAnti(10000,500);
        AntiBan;
        next[i] := InvCount;
        Writeln('Original inv: '+ IntToStr(start[i]));
        Writeln('New inv: ' + IntToStr(next[i]));
        if (start[i] = next[i]) then Exit;
      end;
    end;

    EDIT: In case anyone was wondering, this was just to shorten his code. I would have done it another way personally if he said he wanted shorter+better code...
    Last edited by Iron Man; 05-15-2009 at 01:26 PM.

  5. #5
    Join Date
    Mar 2008
    Location
    Look behind you.
    Posts
    795
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by Iron Man View Post
    I think this should work:

    SCAR Code:
    procedure CheckShark;
    var
      i: integer;
      start, next: TIntegerArray;
    begin
      if InvFull or (not LoggedIn) then Exit;
      Respond;
      AntiBan;
      SetArrayLength(Start, 4);
      SetArrayLength(Next, 4);
      for i := 0 to 3 do
      begin
        start[i] := InvCount;
        Writeln('Your inv: '+ IntToStr(start[i]));
        RWaitAnti(10000,500);
        AntiBan;
        next[i] := InvCount;
        Writeln('Original inv: '+ IntToStr(start[i]));
        Writeln('New inv: ' + IntToStr(next[i]));
        if (start[i] = next[i]) then Exit;
      end;
    end;
    I'll try that, thank you. I use this to check if it's still fishing.

    @ Nadeem: Yeah well, it works to check if it's still fishing, so i'm going to use this method.
    Last edited by DeSnob; 05-14-2009 at 07:09 PM.

  6. #6
    Join Date
    Dec 2008
    Location
    In a galaxy far, far away...
    Posts
    584
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Then why don't you just do something like:

    SCAR Code:
    procedure CheckShark;
    var
      t, start: Integer;
    begin
      if InvFull or (not LoggedIn) then Exit;
      start := InvCount;
      Writeln('Original Inventory: ' IntToStr(start));
      MarkTime(t);
      while ((InvCount <= start) xor (TimeFromMark(t) < 10000)) do
      begin
         Respond;
         AntiBan;
      end;
      Writeln('New Inventory: ' IntToStr(InvCount));
    end;

    That will stop fishing as soon as the inventory count changes. (as soon as a new fish has been caught).

    ~NS

  7. #7
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by Nadeem View Post
    Then why don't you just do something like:

    SCAR Code:
    procedure CheckShark;
    var
      t, start: Integer;
    begin
      if InvFull or (not LoggedIn) then Exit;
      start := InvCount;
      Writeln('Original Inventory: ' IntToStr(start));
      MarkTime(t);
      while ((InvCount <= start) xor (TimeFromMark(t) < 10000)) do
      begin
         Respond;
         AntiBan;
      end;
      Writeln('New Inventory: ' IntToStr(InvCount));
    end;

    ~NS
    why don't you just use and instead of xor
    SCAR Code:
    while ((InvCount <= start) and (TimeFromMark(t) < 10000)) do
    that's easier to understand

  8. #8
    Join Date
    Feb 2007
    Location
    Access Violation at 0x00000000
    Posts
    2,865
    Mentioned
    3 Post(s)
    Quoted
    18 Post(s)

    Default

    and is NOT the same as xor.

    If I remember xor will only do these things when only one of the statements is met. If they are both met it will not perform these procs.

    So if in a very rare case it's exactly 10000 MS and invcount <= start, it will NOT perform these things.
    Ce ne sont que des gueux


  9. #9
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by Floor66 View Post
    and is NOT the same as xor.

    If I remember xor will only do these things when only one of the statements is met. If they are both met it will not perform these procs.
    yes thats true. but we want to stay in the loop as long as these 2 statments both are true:
    1) invcount <= starcount
    2) timefrommark(t) < 10000

    and when one of these is false (we get fish or we have waited more than 10 sec) we exit.

  10. #10
    Join Date
    Feb 2007
    Location
    Access Violation at 0x00000000
    Posts
    2,865
    Mentioned
    3 Post(s)
    Quoted
    18 Post(s)

    Default

    Hmm u got a point.
    Ce ne sont que des gueux


  11. #11
    Join Date
    Dec 2008
    Location
    In a galaxy far, far away...
    Posts
    584
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    And also, if you use and, does it not wait till both the statements or true before it exits? you could rather refer to an or, where either this or this statement is no longer true, exit.

    To be safe with all of these I guess would be, better to just place the TimeFromMark statement inside the loop :P



    ~NS

  12. #12
    Join Date
    Feb 2007
    Location
    Access Violation at 0x00000000
    Posts
    2,865
    Mentioned
    3 Post(s)
    Quoted
    18 Post(s)

    Default

    It waits indeed. So and will check for a diff. InvCount AND wait 10sec, which is not really efficient, EXCEPT if you WANT TO DO AntiBan every 10sec & new shark (no sense in that IMO).

    I say XOR or OR (soo many or's but w/e).
    Or the easy way.
    Xor the hard way .

    You want to AntiBan every 10sec OR every shark caught, then AND is not possible.
    Ce ne sont que des gueux


  13. #13
    Join Date
    Dec 2008
    Location
    In a galaxy far, far away...
    Posts
    584
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I agree with Floor66 lol DeSnob got a good lesson from this I hope ;P



    ~NS

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

    Default

    If you use xor it's a possible infinite loop

    xor - Checks while one of the two is true and the other false. So it waits until there's another item in the inventory, or it waits 10 seconds. Whatever comes first. If the item comes when the timer hits 10 seconds, you have an infinite loop (or you must logout, but that is unlikely because of the anti-ban). -- (Loops until both statements are true or both are false)
    and - Checks while both are true. So it waits for the item with a max of 10 seconds. -- (Loops until one or more statement is false)
    or - Checks while at least one is true. So it waits for another item in the inventory. -- (Loops until both statements are false)

    I say you go for and.

    EDIT: No possible infinite loop, Smartzkid is right, it doesn't even start at all
    Last edited by nielsie95; 05-15-2009 at 03:56 AM.

  15. #15
    Join Date
    Sep 2006
    Location
    New Jersey, USA
    Posts
    5,347
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    You want to use and.

    If either one is false (10 seconds has passed, or a shark has been caught), you want to break out of the loop. Or will keep waiting until a fish is caught or 10 seconds has passed, whichever is longer (it will wait until both are false). Very undesirable. Xor won't wait at all, because both are true at the beginning of the loop, and true xor true = false. Again, very undesirable, because it completely skips the loop.

    EDIT: Beaten :[

    Oh niels, your xor is wrong:

    xor truth table goes like this:
    SCAR Code:
    _|T|F
    T|f|t
    F|t|f

    Since, on the first loop, the inventory count will be the same as it was before (true), and the time will be less then 10 seconds (true), xor will return false.
    Last edited by Smartzkid; 05-15-2009 at 03:58 AM.
    Interested in C# and Electrical Engineering? This might interest you.

  16. #16
    Join Date
    Dec 2008
    Location
    In a galaxy far, far away...
    Posts
    584
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Hmmm... Interesting I guess we ended up learning more than what was asked for :P Me like it!



    ~NS

  17. #17
    Join Date
    Mar 2008
    Location
    Look behind you.
    Posts
    795
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    This will take me a bit to understand I'm so confused!

    Edit: I have no idea what to do now to check if it's still fishing. This became a debate about xor, or, or and. All i need to know is a method to check if it's fishing!
    Last edited by DeSnob; 05-15-2009 at 04:15 AM.

  18. #18
    Join Date
    Sep 2006
    Location
    New Jersey, USA
    Posts
    5,347
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    Try the code Nadeem gave, but with an and rather than a xor.
    Interested in C# and Electrical Engineering? This might interest you.

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
  •