Results 1 to 10 of 10

Thread: help me better understand how to loop, PLEASE!

  1. #1
    Join Date
    Jan 2012
    Location
    in a galaxy far far away
    Posts
    371
    Mentioned
    3 Post(s)
    Quoted
    48 Post(s)

    Default help me better understand how to loop, PLEASE!

    i want my code to check if low prayer and if in combat, if neither of those then, loot, if none of those then fight

    here is my loop.. so far... lmao i know

    Simba Code:
    begin
      cleardebug;
      //setupSRL();
      repeat
       begin
        lowprayer;
        Combat;
        LootMoney;
        wait(1000);
        ClickNpc;
        writeLn('gainz!');
        wait(10000)
       end;
      until (false)
     end.
    >:)

  2. #2
    Join Date
    Oct 2012
    Posts
    1,258
    Mentioned
    40 Post(s)
    Quoted
    588 Post(s)

    Default

    https://villavu.com/forum/showthread.php?t=58935

    http://i.imgur.com/Wq8SRST.png Programming statements section of that thread sounds to me like what you're looking for.

  3. #3
    Join Date
    Dec 2010
    Posts
    483
    Mentioned
    30 Post(s)
    Quoted
    328 Post(s)

    Default

    Quote Originally Posted by chief herb View Post
    i want my code to check if low prayer and if in combat, if neither of those then, loot, if none of those then fight

    here is my loop.. so far... lmao i know

    Simba Code:
    begin
      cleardebug;
      //setupSRL();
      repeat
       begin
        lowprayer;
        Combat;
        LootMoney;
        wait(1000);
        ClickNpc;
        writeLn('gainz!');
        wait(10000)
       end;
      until (false)
     end.
    Simba Code:
    begin
      cleardebug;
      //setupSRL();
      repeat
        begin
          while (lowprayer or Combat) do
            wait (100 + Random(100));
          LootMoney;
          wait(1000);
          ClickNpc;
          writeLn('gainz!');
          wait(10000)
        end;
      until (false)
     end.

    Where:
    lowPrayer() and combat() return a boolean.

  4. #4
    Join Date
    Dec 2013
    Location
    Pitcairn Island
    Posts
    288
    Mentioned
    20 Post(s)
    Quoted
    166 Post(s)

    Default

    Quote Originally Posted by chief herb View Post
    i want my code to check if low prayer and if in combat, if neither of those then, loot, if none of those then fight
    I'd go something like

    Simba Code:
    begin
      cleardebug;
      setupSRL();

      repeat

        if (LowPrayer() or (not Combat())) then
        begin
          WriteLn('Low prayer & not in combat - Looting');
          LootMoney();
        end else
        begin
          WriteLn('Clicking NPC');
          ClickNpc();
        end;

      until (false)

    end.

  5. #5
    Join Date
    Dec 2010
    Posts
    483
    Mentioned
    30 Post(s)
    Quoted
    328 Post(s)

    Default

    Quote Originally Posted by Laquisha View Post
    I'd go something like

    Simba Code:
    begin
      cleardebug;
      setupSRL();

      repeat

        if (LowPrayer() or (not Combat())) then
        begin
          WriteLn('Low prayer & not in combat - Looting');
          LootMoney();
        end else
        begin
          WriteLn('Clicking NPC');
          ClickNpc();
        end;

      until (false)

    end.
    This code will repeatedly click the NPC until LowPrayer is true, and in the case that LowPrayer is true it will immediately start looting without waiting for combat to end.

  6. #6
    Join Date
    Jan 2012
    Location
    in a galaxy far far away
    Posts
    371
    Mentioned
    3 Post(s)
    Quoted
    48 Post(s)

    Default

    Quote Originally Posted by the bank View Post
    Simba Code:
    begin
      cleardebug;
      //setupSRL();
      repeat
        begin
          while (lowprayer or Combat) do
            wait (100 + Random(100));
          LootMoney;
          wait(1000);
          ClickNpc;
          writeLn('gainz!');
          wait(10000)
        end;
      until (false)
     end.

    Where:
    lowPrayer() and combat() return a boolean.
    how do i make them return as a boolean?
    >:)

  7. #7
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    Quote Originally Posted by chief herb View Post
    how do i make them return as a boolean?
    quick answer: use a function

    better answer: you should read everything here: https://villavu.com/forum/showthread.php?t=58935
    There is a section called "Procedures and Functions"

  8. #8
    Join Date
    Jan 2012
    Location
    in a galaxy far far away
    Posts
    371
    Mentioned
    3 Post(s)
    Quoted
    48 Post(s)

    Default

    Quote Originally Posted by Citrus View Post
    quick answer: use a function

    better answer: you should read everything here: https://villavu.com/forum/showthread.php?t=58935
    There is a section called "Procedures and Functions"
    Simba Code:
    program new;
    {$DEFINE SMART} // comment this line out if you don't want to use SMART
    {$i srl-6/srl.simba}

    function waitClientReady(): boolean;override;begin result:= true;end
    var
      x, y : integer;

    const
    lowpray :=2070783;
    combat :=37890;
    col :=37890;

    function LowPrayer(var x, y: Integer; lowpray, 739, 69, 756, 80: Integer): Boolean;

    function InCombat(var x, y: Integer; combat, 13, 33, 16, 48: Integer): Boolean;


    procedure lowprayer;          //finds low prayer
    var
      x, y : integer;
    begin
      if FindColorTolerance(x, y, lowpray, 739, 69, 756, 80, 0) then        
     begin
       writeLn('low prayer');
       //prayer;
       wait(2000);
     end;
    end;

    procedure combat;        
    var
      x, y : integer;
    begin
     if FindColorTolerance(x, y, col, 13, 33, 16, 48, 5) then
      begin
      writeln('in combat');
      wait(500);
      end
    end

     begin
      cleardebug;
      //setupSRL();
      repeat
        begin
          while (LowPrayer or InCombat) do
            wait (100 + Random(100));
          lowprayer;
          combat;
          wait(100);
          writeLn('???!');
          wait(1000)
        end

      until (false)
     end.

    Error: Found unexpected token "739", expected "Identifier" at line 14
    >:)

  9. #9
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    Quote Originally Posted by chief herb View Post
    ..
    I made some changes to your code and wrote some comments. It should work fine if the colors and coordinates are correct.

    Simba Code:
    1. program new;
    2. {
    3. var
    4.   x, y : integer; //x and y are very common variable names, so it's bad practice to use them as global variables
    5. }
    6. {
    7. const
    8. lowpray :=2070783; //typically '=' is used for constants, not ':='
    9. combat :=37890;    //and the constant name is all caps
    10. col :=37890;
    11. }
    12. const
    13.   LOWPRAY = 2070783;
    14.   COMBAT = 37890;
    15.   COL = 37890;
    16.  
    17. {
    18. function LowPrayer(var x, y: Integer; lowpray, 739, 69, 756, 80: Integer): Boolean;
    19. }
    20. //you are trying to insert an already defined constant into this functions parameters, which just doesn't make any sense
    21. //you have a function called 'LowPrayer', and a procedure below called 'lowprayer', which doesn't make sense. also this function has no implementation
    22.  
    23. {
    24. function InCombat(var x, y: Integer; combat, 13, 33, 16, 48: Integer): Boolean;
    25. }
    26. //(same comments as function LowPrayer..)
    27.  
    28. {
    29. procedure lowprayer; //all you need to do is change this to a function
    30. var
    31.   x, y : integer;
    32. begin
    33.   if FindColorTolerance(x, y, lowpray, 739, 69, 756, 80, 0) then
    34.  begin
    35.    writeLn('low prayer');
    36.    //prayer;
    37.    wait(2000);
    38.  end;
    39. end;
    40. }
    41.  
    42. function LowPrayer(): Boolean; //this is a function. 'Boolean' is the return type
    43. var
    44.   x, y : integer;
    45. begin
    46.   Result := FindColorTolerance(x, y, LOWPRAY, 739, 69, 756, 80, 0);
    47.   //'Result' is a sort of implicit variable that will be returned when you call a function
    48.   //in this case, it's a boolean that will be true if 'FindColorTolerance' is true
    49. end;
    50.  
    51. {
    52. procedure combat;
    53. var
    54.   x, y : integer;
    55. begin
    56.  if FindColorTolerance(x, y, col, 13, 33, 16, 48, 5) then
    57.   begin
    58.   writeln('in combat');
    59.   wait(500);
    60.   end
    61. end
    62. }
    63.  
    64. function InCombat(): Boolean; //same as 'LowPrayer'
    65. var
    66.   x, y: Integer;
    67. begin
    68.   Result := FindColorTolerance(x, y, col, 13, 33, 16, 48, 5);
    69. end;
    70.  
    71.  begin
    72.   ClearDebug();
    73.   repeat
    74.     while (LowPrayer or InCombat) do
    75.       wait (100 + Random(100));
    76.     wait(100);
    77.   until (false);
    78.  end.

  10. #10
    Join Date
    Jan 2012
    Location
    in a galaxy far far away
    Posts
    371
    Mentioned
    3 Post(s)
    Quoted
    48 Post(s)

    Default

    Quote Originally Posted by Citrus View Post
    I made some changes to your code and wrote some comments. It should work fine if the colors and coordinates are correct.

    Simba Code:
    1. program new;
    2. {
    3. var
    4.   x, y : integer; //x and y are very common variable names, so it's bad practice to use them as global variables
    5. }
    6. {
    7. const
    8. lowpray :=2070783; //typically '=' is used for constants, not ':='
    9. combat :=37890;    //and the constant name is all caps
    10. col :=37890;
    11. }
    12. const
    13.   LOWPRAY = 2070783;
    14.   COMBAT = 37890;
    15.   COL = 37890;
    16.  
    17. {
    18. function LowPrayer(var x, y: Integer; lowpray, 739, 69, 756, 80: Integer): Boolean;
    19. }
    20. //you are trying to insert an already defined constant into this functions parameters, which just doesn't make any sense
    21. //you have a function called 'LowPrayer', and a procedure below called 'lowprayer', which doesn't make sense. also this function has no implementation
    22.  
    23. {
    24. function InCombat(var x, y: Integer; combat, 13, 33, 16, 48: Integer): Boolean;
    25. }
    26. //(same comments as function LowPrayer..)
    27.  
    28. {
    29. procedure lowprayer; //all you need to do is change this to a function
    30. var
    31.   x, y : integer;
    32. begin
    33.   if FindColorTolerance(x, y, lowpray, 739, 69, 756, 80, 0) then
    34.  begin
    35.    writeLn('low prayer');
    36.    //prayer;
    37.    wait(2000);
    38.  end;
    39. end;
    40. }
    41.  
    42. function LowPrayer(): Boolean; //this is a function. 'Boolean' is the return type
    43. var
    44.   x, y : integer;
    45. begin
    46.   Result := FindColorTolerance(x, y, LOWPRAY, 739, 69, 756, 80, 0);
    47.   //'Result' is a sort of implicit variable that will be returned when you call a function
    48.   //in this case, it's a boolean that will be true if 'FindColorTolerance' is true
    49. end;
    50.  
    51. {
    52. procedure combat;
    53. var
    54.   x, y : integer;
    55. begin
    56.  if FindColorTolerance(x, y, col, 13, 33, 16, 48, 5) then
    57.   begin
    58.   writeln('in combat');
    59.   wait(500);
    60.   end
    61. end
    62. }
    63.  
    64. function InCombat(): Boolean; //same as 'LowPrayer'
    65. var
    66.   x, y: Integer;
    67. begin
    68.   Result := FindColorTolerance(x, y, col, 13, 33, 16, 48, 5);
    69. end;
    70.  
    71.  begin
    72.   ClearDebug();
    73.   repeat
    74.     while (LowPrayer or InCombat) do
    75.       wait (100 + Random(100));
    76.     wait(100);
    77.   until (false);
    78.  end.
    thank you, I'm pretty sure I have a better understanding of boolean's and how to incorporate them into my future scripts! and also some script etiquette/standards! im going to pm you "my"(usedlightly) current fighting script to look over, hope you dont mind... its not the best but it works fairly decent i must say. i just need to incorporate pixelshift or something to be able to tell if a monster is in combat..
    >:)

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
  •