Results 1 to 21 of 21

Thread: How to Use Cases!

  1. #1
    Join Date
    Aug 2009
    Location
    Inside the Matrix...yes it has me, and it has you too.
    Posts
    1,896
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Cool How to Use Cases!

    Introduction

    Well I got really bored today, and so I wrote this beginner tutorial, simply because I couldn't find many on this subject. Case's are extremely useful when scripting, they can make your script look neater and more professional, and they open up a few opportunities for things such as AntiBan.

    What is a Case?

    A case is in this format:
    SCAR Code:
    begin
      Case {Integer, string or procedure} of
        {Integer or string}: {what you want it to do}
        {Second integer or string}: {what you want it to do}
        {Third integer or string}: {what you want it to do}
        //etc.
      end;
    end;

    Integer Cases

    Integer Cases are case statements that use integers for the different cases, as opposed to strings. These are more common, and you will see them in nearly every script in the AntiBan section. Here is an example:
    SCAR Code:
    program CaseExample;

    var
      i: Integer;

    Procedure TheCase;
    begin
      Case i of
        0: WriteLn('Case 1');
        1: WriteLn('Case 2');
        2: WriteLn('Case 3');
        3: WriteLn('Case 4');
      end;
    end;

    Procedure WriteTheCase;
    begin
      for i := 0 to 3 do
      begin
        TheCase;
        Wait(300);
      end;
    end;

    begin
      WriteTheCase;
    end.

    If you don't know how the WriteTheCase procedure works, refer to my tutorial on loops.
    Now, copy this and pase it into scar. If you hit play, it will come out with this in the debug box:
    Code:
    Successfully compiled (78 ms)
    Case 1
    Case 2
    Case 3
    Case 4
    Successfully executed
    String Cases

    String Cases are case statements that use strings for the different cases, as opposed to integers. These aren't as common, but you will see them from time to time. Here is an example of a simple one:
    SCAR Code:
    program CaseExample2;

    const
      WhichOne = 'Hello'; //Hello, World
     
    procedure TheCase;
    begin
      Case WhichOne of
        'Hello': begin
                     MoveMouse(179, 285);
                     Writeln('Hello Mouse is at 179, 285');
                  end;
        'World': begin
                      MoveMouse(791, 760);
                      Writeln('World Mouse is at 791, 760');
                    end;
      end;
    end;

    begin
      TheCase;
    end.

    Cases With Procedures

    These are more widly used, they are used with procedures that return something. For example, GetSkillLevel:
    SCAR Code:
    program CaseExample3;
    {.include SRL/srl.scar} //we need to put this in this time because we're using an SRL procedure; GetSkillLevel

    procedure GetTheLevel;
    begin
      case (GetSkillLevel('Mining')) of
        1..14: Writeln('You can mine Clay, Copper and Tin.');
        15..19: Writeln('You can mine Clay, Copper, Tin and Iron.');
        20..29: Writeln('You can mine Clay, Copper, Tin, Iron and Silver.');
        30..39: Writeln('You can mine Clay, Copper, Tin, Iron, Silver and Coal.');
        40..54: Writeln('You can mine Clay, Copper, Tin, Iron, Silver, Coal and Gold.');
        55..69: Writeln('You can mine Clay, Copper, Tin, Iron, Silver, Coal, Gold and Mithril.');
        70..84: Writeln('You can mine Clay, Copper, Tin, Iron, Silver, Coal, Gold, Mithril and Adamantite.');
        85..99: Writeln('You can mine Clay, Copper, Tin, Iron, Silver, Coal, Gold, Mithril, Adamantite and Rune.');
      end;
    end;

    begin
      GetTheLevel;
    end.

    This will get your current mining level, and then return the number. The number of your level will then trigger the case of that number, and use the case.

    Random Cases

    Random cases are most often found in AntiBan, they randomly choose a number between 0 and the number specified, then does that case. For example:
    SCAR Code:
    program CaseExample4;

    procedure RandomMoveMouse;
    begin
      Case (Random(10)) of
        0: MoveMouse(0, 0);
        1: MoveMouse(10, 10);
        2: MoveMouse(20, 20);
        3: MoveMouse(30, 30);
        4: MoveMouse(40, 40);
        5: MoveMouse(50, 50);
        6: MoveMouse(60, 60);
        7: MoveMouse(70, 70);
        8: MoveMouse(80, 80);
        9: MoveMouse(90, 90);
      end;
    end;

    begin
      RandomMoveMouse;
    end.

    This will randomly choose one of the coordinates specified in the case, and move the mouse to it. Copy it into SCAR, you can play around with it, and then try making your own random case.

    Calling Specific Cases

    These are procedures made so that you call the integer of the case you want along with the procedure. Here is an example with writing random things:
    SCAR Code:
    procedure WriteRandomStuff(WhichToWrite: Integer); //So when you call it, you call it with the case you want to use
    begin
      case WhichToWrite of
        1: Writeln('Write this!');           //if you call it WhichToWrite(1); then you will get this.
        2: Writeln('We"re writing!');      //if you call it WhichToWrite(2); then you will get this.
        3: Writeln('Write stuff!');         //etc...
        4: Writeln('Aaaand writing!');
        5: Writeln('This is fun.');
      end;
    end;

    Conclusion

    In conclusion, cases are very widely used, and if used properly, can be very beneficial. Any questions, comments, or corrections, don't hesitate to post below.
    Last edited by Bionicle; 12-29-2009 at 09:09 PM.
    NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN

  2. #2
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default

    nice

    you forgot the
    SCAR Code:
    procedure areyouanidiot(number1through10 : integer);
    begin
      case number1through10 of
        1..10 : writeln('your not an idiot!');
        else
          writeln('your an idiot!');
      end;
    end;
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

  3. #3
    Join Date
    Aug 2009
    Location
    Inside the Matrix...yes it has me, and it has you too.
    Posts
    1,896
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Awkwardsaw View Post
    nice

    you forgot the
    SCAR Code:
    procedure areyouanidiot(number1through10 : integer);
    begin
      case number1through10 of
        1..10 : writeln('your not an idiot!');
        else
          writeln('your an idiot!');
      end;
    end;
    Took me a good five minutes to figure out if you were trying to diss me or not. But i get it now haha, ill add that in thanks .
    NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN

  4. #4
    Join Date
    Dec 2006
    Posts
    249
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Question for you.

    Trying to find which fish i caught from the chat box.

    PHP Code:
    program New;
     {.include 
    srl/srl.scar}
     var 
    ninteger;
     
    FishCaughtNameChatstring;

    procedure fish;
    begin
      
    if FindChatBoxText('ou catch some'8clBlackthen
        begin
          Name 
    := GetChatBoxText(8clBlack);
          
    writeln(Name);
        
    end;

      case 
    Name of
        
    'shrimp':FishCaught := 'Gots some shrimps on the barby';
        
    'anchovie':FishCaught := 'Salty anchovie';
        
    end;

      
    writeln(FishCaught ' Cool');
    end;
    begin
      fish
    end

    Not working, as I can only get the case function to work where I enter the whole of the text string. I dont want to have in the case funtion 'you catch some Shrimps.', etc

    Any Ideas?

    ScarPreRelease 3.23 rev 80, Includes - Dev Rev 457

  5. #5
    Join Date
    Jun 2007
    Location
    La Mirada, CA
    Posts
    2,484
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    Quote Originally Posted by twobac View Post
    Question for you.

    Trying to find which fish i caught from the chat box.

    PHP Code:
    program New;
     {.include 
    srl/srl.scar}
     var 
    ninteger;
     
    FishCaughtNameChatstring;

    procedure fish;
    begin
      
    if FindChatBoxText('ou catch some'8clBlackthen
        begin
          Name 
    := GetChatBoxText(8clBlack);
          
    writeln(Name);
        
    end;

      case 
    Name of
        
    'shrimp':FishCaught := 'Gots some shrimps on the barby';
        
    'anchovie':FishCaught := 'Salty anchovie';
        
    end;

      
    writeln(FishCaught ' Cool');
    end;
    begin
      fish
    end

    Not working, as I can only get the case function to work where I enter the whole of the text string. I dont want to have in the case funtion 'you catch some Shrimps.', etc

    Any Ideas?
    You would have to do some string manipulation and shorten the string and get it down to just the fish name.

    Nice tutorial.

    "Failure is the opportunity to begin again more intelligently" (Henry Ford)


  6. #6
    Join Date
    Aug 2009
    Location
    Inside the Matrix...yes it has me, and it has you too.
    Posts
    1,896
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by twobac View Post
    Question for you.

    Trying to find which fish i caught from the chat box.

    PHP Code:
    program New;
     {.include 
    srl/srl.scar}
     var 
    ninteger;
     
    FishCaughtNameChatstring;

    procedure fish;
    begin
      
    if FindChatBoxText('ou catch some'8clBlackthen
        begin
          Name 
    := GetChatBoxText(8clBlack);
          
    writeln(Name);
        
    end;

      case 
    Name of
        
    'shrimp':FishCaught := 'Gots some shrimps on the barby';
        
    'anchovie':FishCaught := 'Salty anchovie';
        
    end;

      
    writeln(FishCaught ' Cool');
    end;
    begin
      fish
    end

    Not working, as I can only get the case function to work where I enter the whole of the text string. I dont want to have in the case funtion 'you catch some Shrimps.', etc

    Any Ideas?
    Well, i don't have an explanation for you, but your coding is perfectly fine..you just have to mess around with the strings a bit.
    For example, in my one script i was making my own banking procedure, 'eposit-x' wasn't working, but 'x' did. Just try mixing it around a bit.

    eg: 'imp', 'chovi'
    'some s', 'some a'
    Last edited by Bionicle; 03-20-2010 at 09:43 PM.
    NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN NYAN

  7. #7
    Join Date
    Dec 2006
    Posts
    249
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    maybe i am going about htis the wrong way. different example

    I want to find the skill I have just leveled

    The chat box shows the text
    "You've just advanced a Fishing Level! You have reached level 7."

    I can find the text line containing this text by using a chat function and I can assign the whole line to a variable.
    'ou''ve', 'ust', 'dvanced a', SKILL 'evel' (only using this 'text')
    MyVariable = "You've just advanced a Fishing Level! You have reached level 7."
    so WriteLn(MyVariable) prints the whole line in debug.
    I want to use "case" to interogate the variable MyVariable with a list of SKILLS to find out which skill has been leveled.

    Should I be doing something else or a different function like a IfTextContainsX

    Sorry just started to script.

    Thanks

    ScarPreRelease 3.23 rev 80, Includes - Dev Rev 457

  8. #8
    Join Date
    Jun 2007
    Location
    La Mirada, CA
    Posts
    2,484
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    cases check to see if certain strings match, not if certain strings are contained in a string. So you would have to cut and manipulate the string to get it to be what you want.

    "Failure is the opportunity to begin again more intelligently" (Henry Ford)


  9. #9
    Join Date
    Dec 2006
    Posts
    249
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    ok great thanks,

    where can I find info on text control functions, I guess I would need something like the excel Mid() function and others? I have looked at the functions in text.scar, but do not see anything there.

    ScarPreRelease 3.23 rev 80, Includes - Dev Rev 457

  10. #10
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Check my sig
    http://villavu.com/forum/showthread.php?t=38799

    Should be Pos()..
    Last edited by Naum; 03-20-2010 at 10:21 PM. Reason: copy -> pos :p

  11. #11
    Join Date
    Dec 2006
    Posts
    249
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Thanks so much for all the help, will look at the other thread after I play with srl_Explode (pressed CTRL + Space and got a list of functions!).

    Ed: OMG all I needed was Between!!!!!!!


    Thanks a load Naum
    Last edited by twobac; 03-20-2010 at 10:42 PM.

    ScarPreRelease 3.23 rev 80, Includes - Dev Rev 457

  12. #12
    Join Date
    Dec 2006
    Location
    Houston, TX USA
    Posts
    4,791
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Nice, but you should explain the

    'a', 'b', 'c':

    1, 2, 4, 7:

    IIRC it works with all primitives... useless for boolean but useful for variants? That's only if you wanted to go into more depth though.

  13. #13
    Join Date
    Mar 2006
    Location
    Behind you
    Posts
    3,193
    Mentioned
    61 Post(s)
    Quoted
    63 Post(s)

    Default

    haha i so never really got the whole case thing or arrays but this broke it down a bit better for me. old dogs can learn new tricks.

    Rewrote a procedure in my personal fletcher for random choosing with this tut.

    OLD CODE

    Code:
    procedure Randomfletch;
     var
     moon, c:integer;
       Begin
          Begin
            Moon:=random(3);
          end;
       if moon=1
       then
          Begin
             c:=54
          end;
       if moon=2
       then
          begin
             c:=65
          end;
       if moon=0
       then
          begin
             c:=45
          end;
       typesend(IntToStr(c));
    end;
    NEW CODE

    Code:
    procedure Randomfletch;
     var
       c:integer;
    Begin
       case (random(3)) of
          0:c:=54;
          1:c:=65;
          2:c:=45;
       end;
       typesend(IntToStr(c));
    end;
    PS: i know my code looks like crap but remember that this is my first time scripting in 2 years+. Hit up Iraq twice. Gotta love the cash paid for 2 cars now i'm on my third.

  14. #14
    Join Date
    Mar 2007
    Posts
    1,700
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Two things..
    Code:
    i := Random(8);
    case i of
      0..2: //standards
        begin
           DoStuff;
        end;
      3: DoSomething;
      else
        begin
          Writeln('i is not 0, 1, or 2');
        end;
    end;
    Great tut
    Last edited by lordsaturn; 06-08-2010 at 07:12 PM.

  15. #15
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    Quote Originally Posted by BraK View Post
    haha i so never really got the whole case thing or arrays but this broke it down a bit better for me. old dogs can learn new tricks.

    Rewrote a procedure in my personal fletcher for random choosing with this tut.

    OLD CODE

    Code:
    procedure Randomfletch;
     var
     moon, c:integer;
       Begin
          Begin
            Moon:=random(3);
          end;
       if moon=1
       then
          Begin
             c:=54
          end;
       if moon=2
       then
          begin
             c:=65
          end;
       if moon=0
       then
          begin
             c:=45
          end;
       typesend(IntToStr(c));
    end;
    NEW CODE

    Code:
    procedure Randomfletch;
     var
       c:integer;
    Begin
       case (random(3)) of
          0:c:=54;
          1:c:=65;
          2:c:=45;
       end;
       typesend(IntToStr(c));
    end;
    PS: i know my code looks like crap but remember that this is my first time scripting in 2 years+. Hit up Iraq twice. Gotta love the cash paid for 2 cars now i'm on my third.
    You went to Iraq?

    Also, that could be changed to..

    SCAR Code:
    procedure RandomFletch;
    begin
      TypeSend(IntToStr(27 + Random(72)));
    end;


  16. #16
    Join Date
    Mar 2006
    Location
    Behind you
    Posts
    3,193
    Mentioned
    61 Post(s)
    Quoted
    63 Post(s)

    Default

    Quote Originally Posted by i luffs yeww View Post
    You went to Iraq?

    Also, that could be changed to..

    SCAR Code:
    procedure RandomFletch;
    begin
      TypeSend(IntToStr(27 + Random(72)));
    end;

    Yea just got back from my second time over there this past winter.

    I put it using 45, 54, 65 because it's what I normally press without looking, when I do it manually. The goal is to make it do what i normally do manually for mine. I video recorded myself doing it about 50 times before I started making this script.

  17. #17
    Join Date
    Jan 2007
    Location
    the middle of know-where
    Posts
    1,308
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Nice Tut, it's short simple and to the point.

    Quote Originally Posted by BraK View Post
    I video recorded myself doing it about 50 times before I started making this script.
    ^ FTW - a lot of times I do things without thinking and completely forget to add it to my scripts.
    On vacation in NeverLand,
    Code:
    typedef int bool;
    enum { false, true };

  18. #18
    Join Date
    Feb 2006
    Location
    Pennsylvania
    Posts
    1,524
    Mentioned
    2 Post(s)
    Quoted
    1 Post(s)

    Default

    *switch statement

  19. #19
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,691
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    Quote Originally Posted by Bebe View Post
    *switch statement
    I don't think it is a switch statement, now is it? This is pascal, not C. A switch statement works fundamentally different.



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  20. #20
    Join Date
    Feb 2009
    Location
    AZ, USA
    Posts
    460
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by BraK View Post
    I put it using 45, 54, 65 because it's what I normally press without looking, when I do it manually. The goal is to make it do what i normally do manually for mine. I video recorded myself doing it about 50 times before I started making this script.
    Unless you only want those three numbers, you may like using this

    It will do things like 34, 33, 343, 345, 45, 454, etc
    SCAR Code:
    procedure RandomFletch;
    var
      a, b, i: integer;
    begin
      a:= 3 + Random(5);
      b:= a;
      if (RBool) then
      begin
        for i:= 1 to 1 + Random(2) do
          b:= b + a * strtoint(floattostr(pow(10, i)));
      end else
      begin
        if (RBool) then
        begin
          for i:= 1 to Random(2) + 1 do
            b:= b + (a + (-i + 2)) * strtoint(floattostr(pow(10, i)));
        end else
        begin
          for i:= 1 to 2 do
            b:= b + (a - i) * strtoint(floattostr(pow(10, i)));
        end;
      end;
      TypeSend(IntToStr(b));
    end;
    Is your account in an old-school random? Help SRL-OSR solve randoms!

  21. #21
    Join Date
    Mar 2006
    Location
    Behind you
    Posts
    3,193
    Mentioned
    61 Post(s)
    Quoted
    63 Post(s)

    Default

    Quote Originally Posted by Ogre View Post
    Unless you only want those three numbers, you may like using this

    It will do things like 34, 33, 343, 345, 45, 454, etc
    SCAR Code:
    procedure RandomFletch;
    var
      a, b, i: integer;
    begin
      a:= 3 + Random(5);
      b:= a;
      if (RBool) then
      begin
        for i:= 1 to 1 + Random(2) do
          b:= b + a * strtoint(floattostr(pow(10, i)));
      end else
      begin
        if (RBool) then
        begin
          for i:= 1 to Random(2) + 1 do
            b:= b + (a + (-i + 2)) * strtoint(floattostr(pow(10, i)));
        end else
        begin
          for i:= 1 to 2 do
            b:= b + (a - i) * strtoint(floattostr(pow(10, i)));
        end;
      end;
      TypeSend(IntToStr(b));
    end;
    That's an interesting approach i haven't really used Floats before but i'll look into it. But that is a huge peice of script you got there. Thank's for the info.

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
  •