Results 1 to 16 of 16

Thread: Different number of Cases

  1. #1
    Join Date
    Feb 2012
    Posts
    168
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Different number of Cases

    This is sorta hard to explain, but I'm pretty much wondering if you're able to set a variable number of cases.

    This gets my point across, but there are easier ways to do it and is not what I am trying to accomplish:

    Say I'm writing a flax picking bot, so I write my TPA finder and all, and I'm left with X TPA's. (X being a variable). Would there be a way to construct a Switch statement such that it would have X different outcomes? (X would be different each time).

    Again, I know there are many easier ways to do this specific task (Flax picking), but I'm asking in general if you're allowed or if it's possible to make a switch statement with different amount of cases.

  2. #2
    Join Date
    Jan 2008
    Location
    C:\
    Posts
    1,483
    Mentioned
    2 Post(s)
    Quoted
    2 Post(s)

    Default

    Well I don't really understand this at all, but I'll take a shot at it >.<

    Simba Code:
    var
      i, hPoints, hColors: Integer;
      aPoints: array of TPointArray;
      TPA: TPointArray;
      Colors: TIntegerArray;
    begin
      Colors := [1875487, 2686219, {etc.}];
      hColors := High(Colors);
      for i := 0 to hColors do
      begin
        FindColorxxx(TPA, Colors[i], {etc.});
        aPoints[i] := TPA;
        //...
      end;
      hPoints := High(aPoints);
      for i := 0 to hPoints do
      begin
        MMouse(MiddleTPA(aPoints[i]).x, MiddleTPA(aPoints[i]).y, {etc.});
        //...
      end;
      //...
    end;

    Lemme know if that's anything like what you were looking for haha

  3. #3
    Join Date
    Feb 2012
    Posts
    168
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I don't need anything to do with finding the flax, that's just an example.

    Say for example that I wanted to have a lottery, alright, but I didn't know how many people would enter. Person '1' is a, person '2' is called b, and I wanted to print out a customized message for each person.

    So I'm asking how could I have an undefined number of cases in a switch statement?

  4. #4
    Join Date
    Feb 2012
    Posts
    168
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    And would something like:

    Switch(random(A)) of:
    1..x : ------
    x..y : ------
    y..z : ------
    z..A : ------

    work? And how would I be able to input more options?

  5. #5
    Join Date
    Dec 2007
    Posts
    289
    Mentioned
    4 Post(s)
    Quoted
    86 Post(s)

    Default

    Set a variable (X in your case) to the length of the TPA?

  6. #6
    Join Date
    Jan 2008
    Location
    C:\
    Posts
    1,483
    Mentioned
    2 Post(s)
    Quoted
    2 Post(s)

  7. #7
    Join Date
    Feb 2012
    Location
    Somewhere, over the rainbow...
    Posts
    2,272
    Mentioned
    3 Post(s)
    Quoted
    45 Post(s)

    Default

    I'm confused, do you mean something like?

    (run this)
    Simba Code:
    program New;
    {$i srl\srl.simba}

    procedure NameEm;
    var
      name: Integer;
    begin
      for name := 0 to 5 do
      begin
        Writeln('The value is : ' + IntToStr(name));
        Wait(500);
      end;
    end;

    begin
      ClearDebug;
      SetUpSRL;
      NameEm;
    end.

  8. #8
    Join Date
    Oct 2011
    Posts
    805
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

    Default

    This ?
    Simba Code:
    program new;

    var
    a ,b ,c : integer;
    begin

      a := 10;
      b := 5;
      c := 15;

      case a of
       0: writeln('df');
       b..c : writeln('d');
      end;
    end.

    Quote Originally Posted by Imagine View Post
    And how would I be able to input more options?
    You can't add options to case statement dynamically inside program. But you can do the same in few other ways. It would be simplier if you say exactly what you want to do.

  9. #9
    Join Date
    Dec 2011
    Location
    The Netherlands
    Posts
    1,631
    Mentioned
    47 Post(s)
    Quoted
    254 Post(s)

    Default

    Quote Originally Posted by Imagine View Post
    This is sorta hard to explain, but I'm pretty much wondering if you're able to set a variable number of cases.

    This gets my point across, but there are easier ways to do it and is not what I am trying to accomplish:

    Say I'm writing a flax picking bot, so I write my TPA finder and all, and I'm left with X TPA's. (X being a variable). Would there be a way to construct a Switch statement such that it would have X different outcomes? (X would be different each time).

    Again, I know there are many easier ways to do this specific task (Flax picking), but I'm asking in general if you're allowed or if it's possible to make a switch statement with different amount of cases.
    You don't have an X amount of TPA's. A TPA is a TPointArray and FindColors will result an Array of TPoints. This means you have an X amount of TPoints. Every TPoint matches the color on the screen that you are searching for.

    When you are standing in the flax field you will have multiple flax plants. You use FindColors to make a TPA.
    WriteLn(''+ToStr(TPA)+'');
    That gives you all the points eg.
    Point(100, 100);
    Point(105, 110);
    Now if you want to randomly pick one of the flaxes you can do something similiar to this (Taken from my barbarian outpost development blog)
    Simba Code:
    if (RopeLength[0] < 100) and (RopeLength[1] < 100) then
            begin
              case Random(4) of
                0: begin
                     P := RandomRange(Low(SwingClSplit[0]), High(SwingClSplit[0]));
                     MMouse(SwingClSplit[0][P].X, SwingClSplit[0][P].Y, 0, 0); // Random spot on rope 1
                   end;
    This is actually an array of splitted TPA so an ATPA (Array of TPointArray) aka Array of Array of TPoint

    It will randomly click on one of the TPoints in the ATPA. Let me know if this is what you are looking to learn otherwise I will just be typing way too much xD

    Script source code available here: Github

  10. #10
    Join Date
    Dec 2011
    Location
    Holland
    Posts
    545
    Mentioned
    0 Post(s)
    Quoted
    19 Post(s)

    Default

    Quote Originally Posted by Imagine View Post
    I don't need anything to do with finding the flax, that's just an example.

    Say for example that I wanted to have a lottery, alright, but I didn't know how many people would enter. Person '1' is a, person '2' is called b, and I wanted to print out a customized message for each person.

    So I'm asking how could I have an undefined number of cases in a switch statement?
    That would be done like:

    Simba Code:
    var Participants: TStringArray;
      i: integer;
    begin
      for i :=0 to high(Participants) do
        case lowercase(Participants[i]) of
        'bart': MessageHim('hey Bart,  ')
        'susan': MessageHim('hi mom..')
        'lois': MessageHim('Hey <3')
        'mark': MessageHim('yo mark, you joint anyways?')
        'noob': MessageHim('wow your name is noob? awesome.')
    end;

    If for example Bart didnt join, he wont get the message.
    These are customized messages for each person, I hope this explains something you want to know because Im not sure if this is what your asking for

  11. #11
    Join Date
    Oct 2011
    Location
    UK
    Posts
    1,322
    Mentioned
    2 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by Imagine View Post
    And would something like:

    Switch(random(A)) of:
    1..x : ------
    x..y : ------
    y..z : ------
    z..A : ------

    work? And how would I be able to input more options?
    Yes that would work, let's take your lottery idea, you would have everybody pick 5 numbers, at the end of it you want to email everybody saying how many numbers they got right:

    Simba Code:
    program new;
    Var
      NumberCorrect :  array of integer;
      Messages : array of String;
      i : integer;
    begin
                        //The first person got 4 right, the next got 0 etc...
      NumberCorrect := [4, 0, 3, 2, 2, 5, 3];//This array could be any length (dependant on the number of people in your lottery)
      Messages := ['Sorry you didn''t get any right, better luck next time',  //your messages dependant on the number correct
                   'You only got 1 number correct, sorry',
                   'You managed to get 2 correct, well done',
                   'You got 3 correct and won £20, well done',
                   'You got 4 numbers correct and won £200, well done',
                   'You won the jackpot!!!!'];
      for i := 0 to high(NumberCorrect) do  //for each person it prints out their result
        WriteLn('Person '+IntToStr(i)+' - '+Messages[NumberCorrect[i]]);

    end.

    Code:
    Compiled successfully in 31 ms.
    Person 0 - You got 4 numbers correct and won £200, well done
    Person 1 - Sorry you didn't get any right, better luck next time
    Person 2 - You got 3 correct and won £20, well done
    Person 3 - You managed to get 2 correct, well done
    Person 4 - You managed to get 2 correct, well done
    Person 5 - You won the jackpot!!!!
    Person 6 - You got 3 correct and won £20, well done
    Successfully executed.

  12. #12
    Join Date
    Feb 2012
    Posts
    168
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by beginner5 View Post
    This ?
    Simba Code:
    program new;

    var
    a ,b ,c : integer;
    begin

      a := 10;
      b := 5;
      c := 15;

      case a of
       0: writeln('df');
       b..c : writeln('d');
      end;
    end.



    You can't add options to case statement dynamically inside program. But you can do the same in few other ways. It would be simplier if you say exactly what you want to do.
    Yeah, that was pretty much what I meant, you can't have a dynamic case statement can you?

    Quote Originally Posted by J J View Post
    You don't have an X amount of TPA's. A TPA is a TPointArray and FindColors will result an Array of TPoints. This means you have an X amount of TPoints. Every TPoint matches the color on the screen that you are searching for.

    When you are standing in the flax field you will have multiple flax plants. You use FindColors to make a TPA.
    WriteLn(''+ToStr(TPA)+'');
    That gives you all the points eg.
    Point(100, 100);
    Point(105, 110);
    Now if you want to randomly pick one of the flaxes you can do something similiar to this (Taken from my barbarian outpost development blog)
    Simba Code:
    if (RopeLength[0] < 100) and (RopeLength[1] < 100) then
            begin
              case Random(4) of
                0: begin
                     P := RandomRange(Low(SwingClSplit[0]), High(SwingClSplit[0]));
                     MMouse(SwingClSplit[0][P].X, SwingClSplit[0][P].Y, 0, 0); // Random spot on rope 1
                   end;
    This is actually an array of splitted TPA so an ATPA (Array of TPointArray) aka Array of Array of TPoint

    It will randomly click on one of the TPoints in the ATPA. Let me know if this is what you are looking to learn otherwise I will just be typing way too much xD
    When I said TPA's, I meant like after they were split up into an ATPA, there are several TPA's in there :P but I was more looking for a dynamic switch statement.

    Quote Originally Posted by Chris View Post
    That would be done like:

    Simba Code:
    var Participants: TStringArray;
      i: integer;
    begin
      for i :=0 to high(Participants) do
        case lowercase(Participants[i]) of
        'bart': MessageHim('hey Bart,  ')
        'susan': MessageHim('hi mom..')
        'lois': MessageHim('Hey <3')
        'mark': MessageHim('yo mark, you joint anyways?')
        'noob': MessageHim('wow your name is noob? awesome.')
    end;

    If for example Bart didnt join, he wont get the message.
    These are customized messages for each person, I hope this explains something you want to know because Im not sure if this is what your asking for
    Quote Originally Posted by putonajonny View Post
    Yes that would work, let's take your lottery idea, you would have everybody pick 5 numbers, at the end of it you want to email everybody saying how many numbers they got right:

    Simba Code:
    program new;
    Var
      NumberCorrect :  array of integer;
      Messages : array of String;
      i : integer;
    begin
                        //The first person got 4 right, the next got 0 etc...
      NumberCorrect := [4, 0, 3, 2, 2, 5, 3];//This array could be any length (dependant on the number of people in your lottery)
      Messages := ['Sorry you didn''t get any right, better luck next time',  //your messages dependant on the number correct
                   'You only got 1 number correct, sorry',
                   'You managed to get 2 correct, well done',
                   'You got 3 correct and won £20, well done',
                   'You got 4 numbers correct and won £200, well done',
                   'You won the jackpot!!!!'];
      for i := 0 to high(NumberCorrect) do  //for each person it prints out their result
        WriteLn('Person '+IntToStr(i)+' - '+Messages[NumberCorrect[i]]);

    end.

    Code:
    Compiled successfully in 31 ms.
    Person 0 - You got 4 numbers correct and won £200, well done
    Person 1 - Sorry you didn't get any right, better luck next time
    Person 2 - You got 3 correct and won £20, well done
    Person 3 - You managed to get 2 correct, well done
    Person 4 - You managed to get 2 correct, well done
    Person 5 - You won the jackpot!!!!
    Person 6 - You got 3 correct and won £20, well done
    Successfully executed.
    That's an interesting idea, although it's still not quite dynamic :/

  13. #13
    Join Date
    Oct 2011
    Posts
    805
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

    Default

    Yeah, that was pretty much what I meant, you can't have a dynamic case statement can you?
    You can have dynamic option range ,like a..b ,where a,b are variables ,but you can't have dynamic amount of options ,however it's possible in another way , depending what are you going to do?

  14. #14
    Join Date
    Oct 2011
    Location
    UK
    Posts
    1,322
    Mentioned
    2 Post(s)
    Quoted
    1 Post(s)

    Default

    I dont know how dynamic you want it? You'll have to post exactly what you are trying to do...

  15. #15
    Join Date
    Jan 2008
    Location
    C:\
    Posts
    1,483
    Mentioned
    2 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by Imagine
    Yeah, that was pretty much what I meant, you can't have a dynamic case statement can you?
    You can't change the amount of options or the functions used in those options, but you can change some other things:

    Simba Code:
    program new;

    var
    a ,b ,c ,i: integer;
    strings : array of String;
    begin

      a := 10;
      b := 5;
      c := 15;

      strings := ['yo', 'hi', 'hey'];

      case a of
        0 :
        begin
          i := randomRandom(0, high(strings));
          writeln(strings[i]);
        end;
        b..c :
        begin
          i := randomRandom(0, high(strings));
          writeln(strings[i]);
        end;
      end;
    end.

    Or using a statement inside of the case:

    Simba Code:
    program new;

    var
    a ,b ,c ,i: integer;
    strings : array of String;
    begin

      a := 10;
      b := 5;
      c := 15;

      strings := ['yo', 'hi', 'hey'];

      case a of
        0 :
        begin
          if {something} then
            i := {whatever}
          writeln(strings[i]);
        end;
        b..c :
        begin
          if {something} then
            i := {whatever}
          writeln(strings[i]);
        end;
      end;
    end.

  16. #16
    Join Date
    Feb 2012
    Posts
    168
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Alright, thank you very much

    Although this sorta-limits what I was trying to do, I guess I can still use it

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
  •