Results 1 to 15 of 15

Thread: for i := x to y do - How to use them.

  1. #1
    Join Date
    Dec 2011
    Location
    Toronto, Ontario
    Posts
    6,424
    Mentioned
    84 Post(s)
    Quoted
    863 Post(s)

    Default for i := x to y do - How to use them.

    for..to..do loops are very efficient to use.
    They're especially useful for tasks such as cleaning herbs, where you have to click each and every inventory slot.
    Simba Code:
    for i := 1 to 28 do

    is what you'll see in most cases (if regarding the inventory).
    This'll be very short, but simple guide on how to use them.
    Take my scatterer script's Scatter procedure -
    Simba Code:
    procedure Scatter;
    var
      i:Integer;
    begin
      MouseSpeed := 255;
      MouseItem(1,1);
      MouseItem(5,1);
      MouseItem(9,1);
      MouseItem(13,1);
      MouseItem(17,1);
      MouseItem(21,1);
      MouseItem(25,1);
      MouseSpeed := 18;
      MouseItem(2,1);
      MouseSpeed := 255;
      MouseItem(6,1);
      MouseItem(10,1);
      MouseItem(14,1);
      MouseItem(18,1);
      MouseItem(22,1);
      MouseItem(26,1);
      MouseSpeed := 18;
      MouseItem(3,1);
      MouseSpeed := 255;
      MouseItem(7,1);
      MouseItem(11,1);
      MouseItem(15,1);
      MouseItem(19,1);
      MouseItem(23,1);
      MouseItem(27,1);
      MouseSpeed := 18;
      MouseItem(4,1);
      MouseSpeed := 255;
      MouseItem(8,1);
      MouseItem(12,1);
      MouseItem(16,1);
      MouseItem(20,1);
      MouseItem(24,1);
      MouseItem(28,1);
    end;
    What happens in that procedure is, it'll click each an every inventory slot at VERY high speeds, and its natural for some of the clicks to not go through.
    What we can add at the end of the procedure is -
    Simba Code:
    repeat
      for i := 1 to 28 do
      begin
        if ExistsItem(i) then
          MouseItem(i,1);
      end;
      Until(InvEmpty);
    What that'll do is it'll cycle through i, which is an array of sorts of 1 to 28.
    If an item exists in *i*, then it'll click it.
    Test it out, play around with it, it'll come in real useful one day.


    Sorry if you can't understand it, it's 11PM here and I was awake the whole day starting from 5AM ;s

  2. #2
    Join Date
    Nov 2006
    Posts
    2,369
    Mentioned
    4 Post(s)
    Quoted
    78 Post(s)

    Default

    Nice tutorial.

    One would be nice that explains while and until in the same tutorial too

    p.s Integer i isn't really an array
    Last edited by weequ; 03-16-2012 at 03:34 AM.
    Quote Originally Posted by DeSnob View Post
    ETA's don't exist in SRL like they did in other communities. Want a faster update? Help out with updating, otherwise just gotta wait it out.

  3. #3
    Join Date
    Dec 2011
    Location
    Toronto, Ontario
    Posts
    6,424
    Mentioned
    84 Post(s)
    Quoted
    863 Post(s)

    Default

    I'll do that

  4. #4
    Join Date
    Nov 2006
    Posts
    2,369
    Mentioned
    4 Post(s)
    Quoted
    78 Post(s)

    Default

    I should make some tutorials too, could be fun.
    Quote Originally Posted by DeSnob View Post
    ETA's don't exist in SRL like they did in other communities. Want a faster update? Help out with updating, otherwise just gotta wait it out.

  5. #5
    Join Date
    Nov 2011
    Posts
    1,589
    Mentioned
    9 Post(s)
    Quoted
    17 Post(s)

    Default

    Didn't know that, gonna find it useful
    Thanks x



    ^^

  6. #6
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    Simba Code:
    for i := 1 to 28 do
      begin
        if ExistsItem(i) then
          MouseItem(i,1);
      end;

    equals

    Simba Code:
    i := 1;
      repeat
        if ExistsItem(i) then
          MouseItem(i,1);
        Inc(i);
      until(i > 28);

    So i really isn't an array, just a variable of the type integer.
    Working on: Tithe Farmer

  7. #7
    Join Date
    Oct 2010
    Posts
    1,255
    Mentioned
    0 Post(s)
    Quoted
    15 Post(s)

    Default

    Fix your standards, use some failsafes, and why would your inventory ever become empty cleaning herbs?
    I'm back

  8. #8
    Join Date
    Dec 2011
    Location
    Toronto, Ontario
    Posts
    6,424
    Mentioned
    84 Post(s)
    Quoted
    863 Post(s)

    Default

    Quote Originally Posted by smurg View Post
    Fix your standards, use some failsafes, and why would your inventory ever become empty cleaning herbs?
    Did you ever read what script is about?
    Jeez, atleast look before posting and making a fool out of yourself..

  9. #9
    Join Date
    Oct 2010
    Posts
    1,255
    Mentioned
    0 Post(s)
    Quoted
    15 Post(s)

    Default

    Quote Originally Posted by Sin View Post
    Did you ever read what script is about?
    Jeez, atleast look before posting and making a fool out of yourself..
    This is a tutorial. People copy blocks of code from tutorials or attempt to learn from them. You should teach solid fundamentals of all aspects of scripting in the code blocks whether it's the intended subject or not.

    You mentioned cleaning herbs and then a scatterer function in your Scatter script. I'm guessing it's supposed to scatter ashes now, but from the flow of the paragraphs, I missed that originally.

    This isn't even a tutorial on for loops, it's you taking a for loop code block from a script and telling them how it clicks inventory slots. You should go over declaring variables, initializing, using appropriate failsafes, and when to use it over other loops or other loops over it. (Maybe a more descriptive thread title also)

    Don't take it personally. Just if I see sloppy work posted, I put in my 2 cents.
    I'm back

  10. #10
    Join Date
    Dec 2011
    Location
    Toronto, Ontario
    Posts
    6,424
    Mentioned
    84 Post(s)
    Quoted
    863 Post(s)

    Default

    Nowhere in the guide do I say that this is a tutorial :s
    simple guide on how to use them.
    Thanks for your opinion though, it's noted.

  11. #11
    Join Date
    Oct 2010
    Posts
    1,255
    Mentioned
    0 Post(s)
    Quoted
    15 Post(s)

  12. #12
    Join Date
    Dec 2011
    Location
    Toronto, Ontario
    Posts
    6,424
    Mentioned
    84 Post(s)
    Quoted
    863 Post(s)

    Default

    Where else am I supposed to put it then?

  13. #13
    Join Date
    Feb 2012
    Location
    SRL Jail
    Posts
    1,319
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Very nice tutorial. Thanks a lot!

  14. #14
    Join Date
    Feb 2006
    Posts
    3,044
    Mentioned
    4 Post(s)
    Quoted
    21 Post(s)

    Default

    Not sure, but but do you mean that I replace "Scatter" function with one below?

    Just asking for new ones

    ~Home

  15. #15
    Join Date
    Feb 2011
    Location
    Vancouver Island
    Posts
    85
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Thanks shay! I didn't really understand this until now,
    seems easier than i first thought.

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
  •