Results 1 to 15 of 15

Thread: For..To..Do Loops

  1. #1
    Join Date
    Aug 2014
    Posts
    25
    Mentioned
    0 Post(s)
    Quoted
    11 Post(s)

    Default For..To..Do Loops

    Hello, I'm trying to create a script for a rsps which drinks brews by low hp. After 3 sips it should drink 1 restore sip.

    for i := 0 to 3 do dosn't work because it would repeat 3 times regardless of if hp are low or not.

    Thanks in advance

  2. #2
    Join Date
    Oct 2013
    Location
    East Coast USA
    Posts
    770
    Mentioned
    61 Post(s)
    Quoted
    364 Post(s)

    Default

    I'm not sure I really understand your requirement, but you would use mod to do something 'every n times'

    Simba Code:
    var sips: integer;
    begin

    sips := 0;
    while (true) do
    begin
      inc(sips)
      if (sips mod 4) then
        writeln('Im on my fourth sip again');
    end;

  3. #3
    Join Date
    Jun 2012
    Posts
    122
    Mentioned
    0 Post(s)
    Quoted
    40 Post(s)

    Default

    I agree with bonsai, your post is unclear to me too. Sounds like you also want to check the amount of HP left on the character. You can do that like this:

    Simba Code:
    // Check if HP is less than 80  
    if(actionbar.getHPPercent() < 80)
    then begin  
       // Do your stuff here.
    end;

  4. #4
    Join Date
    Aug 2014
    Posts
    25
    Mentioned
    0 Post(s)
    Quoted
    11 Post(s)

    Default

    Thanks for you reply. When I try to use if (sips mod 4) then this error comes up:"Type mismatch". What is mod? or were can I find someting bout it?

  5. #5
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    995
    Mentioned
    145 Post(s)
    Quoted
    596 Post(s)

    Default

    Quote Originally Posted by EyYo96 View Post
    Thanks for you reply. When I try to use if (sips mod 4) then this error comes up:"Type mismatch". What is mod? or were can I find someting bout it?
    Code:
    var sips: integer;
    begin
      sips := 0;
      while True do
      begin
        inc(sips)
    
        if sips mod 4 = 0 then
          WriteLn('Sip: ',sips);
      end;
    end.
    however you seem to want to check if hp is low first:
    Simba Code:
    var i:Integer;
    begin
      if(actionbar.getHPPercent() < 30) then   //if hp is less then 40%
      begin  
       for i:=1 to 3 do
       begin
         //call proc to drink 1 brew (will be called 3 times) here
       end;
       //call proc to drink 1 restore sip here                    
      end;
    end;
    Last edited by slacky; 09-05-2014 at 09:53 AM.
    !No priv. messages please

  6. #6
    Join Date
    Aug 2014
    Posts
    25
    Mentioned
    0 Post(s)
    Quoted
    11 Post(s)

    Default

    Hi thanks for your help. Ok I'll try to explain it again. The script should check HP, if hp are under 80, like your example, it should drink a sip of saradomin brew. When he has drunk 3 sips [combat stats r low so he must drink 1 sip of restore so stats go up to 99 again], it should drink one sip of restoration pot and start at beginning. [3 brew sips then 1 restore sip]

  7. #7
    Join Date
    Jun 2012
    Posts
    122
    Mentioned
    0 Post(s)
    Quoted
    40 Post(s)

    Default

    Quote Originally Posted by EyYo96 View Post
    Thanks for you reply. When I try to use if (sips mod 4) then this error comes up:"Type mismatch". What is mod? or were can I find someting bout it?
    General info on mod. In short it finds the remainder after dividing two numbers.

    Ninja edit:

    Quote Originally Posted by EyYo96 View Post
    Hi thanks for your help. Ok I'll try to explain it again. The script should check HP, if hp are under 80, like your example, it should drink a sip of saradomin brew. When he has drunk 3 sips [combat stats r low so he must drink 1 sip of restore so stats go up to 99 again], it should drink one sip of restoration pot and start at beginning. [3 brew sips then 1 restore sip]
    Then what you want is to keep track of how many sips of saradomin brew you have taken. Once that counter is >= 3 you can take your restore potion and wait until your health is below 80% again.



    Simba Code:
    // Check if HP is less than 80  
    if(actionbar.getHPPercent() < 80)
    then begin  
       drinkSaraPot();
       saraPotCounter := saraPotCounter + 1;
    end;

    // Check how many times you drank sara.
    if(saraPotCounter >= 3)
    then begin
       drinkRestorePot();
       saraPotCounter := 0;
    end

    Make sure saraPotCounter is a global variable. Or depending on how much sara heals and makes you lose in stats you might want to go with slacky's version instead.

  8. #8
    Join Date
    Aug 2014
    Posts
    25
    Mentioned
    0 Post(s)
    Quoted
    11 Post(s)

    Default

    Haha you got it. That's exactly what I wanted Thanks everyone

  9. #9
    Join Date
    Aug 2014
    Posts
    25
    Mentioned
    0 Post(s)
    Quoted
    11 Post(s)

    Default

    hm, if i am trying to use if(actionbar.getHPPercent() < 80) it says "Unknown identifier 'actionbar'". Using osr include and pascal. How can I fix it?

  10. #10
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    Quote Originally Posted by EyYo96 View Post
    hm, if i am trying to use if(actionbar.getHPPercent() < 80) it says "Unknown identifier 'actionbar'". Using osr include and pascal. How can I fix it?
    There's no action bar in OSR. That function is for rs3.
    In OSR include the function is just HPPercent();

  11. #11
    Join Date
    Aug 2014
    Posts
    25
    Mentioned
    0 Post(s)
    Quoted
    11 Post(s)

    Default

    Ok ty, tried to replace if(actionbar.getHPPercent() < 80) with if(HPPercent() < 80), "Invalid number of parameters". What am I doing wrong?

  12. #12
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    Quote Originally Posted by EyYo96 View Post
    Ok ty, tried to replace if(actionbar.getHPPercent() < 80) with if(HPPercent() < 80), "Invalid number of parameters". What am I doing wrong?
    because HPPercent() has a parameter...?
    Simba Code:
    function HPPercent(SwapGTabBack: Boolean): Integer;

    Try HPPercent(true);

  13. #13
    Join Date
    Aug 2014
    Posts
    25
    Mentioned
    0 Post(s)
    Quoted
    11 Post(s)

    Default

    I've tried:

    if (HPPercent() < 80)
    and
    if (HPPercent(true) < 80)
    and
    if (HPPercent(100) < 80)
    dosn't work. could someone help me?

  14. #14
    Join Date
    Aug 2014
    Location
    Australia
    Posts
    932
    Mentioned
    53 Post(s)
    Quoted
    495 Post(s)

    Default

    Can you post at least part of your script in [simba] tags? It would really help to be able to see what it is that you've got in order to suggest changes.

  15. #15
    Join Date
    Aug 2014
    Posts
    25
    Mentioned
    0 Post(s)
    Quoted
    11 Post(s)

    Default

    Dosn't work.

    Simba Code:
    // Check if HP is less than 80  
    if(HPPercent() < 80)
    then begin  
       drinkSaraPot();
     end;

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
  •