Results 1 to 16 of 16

Thread: Problem with Cases

  1. #1
    Join Date
    Mar 2007
    Location
    <3
    Posts
    2,683
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Problem with Cases

    Hi.

    It just jump over the case?

    My question ^^ : Why ?

    SCAR Code:
    case 3 of

     0: if PowerChop = 'Yes' then
        MainloopPower;
     1: if PowerChop = 'No' then
        if Tr33Type = 1 then
        MainloopYew;
     2: If PowerChop = 'No' then
        if Tr33Type = 2 then
        MainloopWil;
     end;

  2. #2
    Join Date
    Nov 2006
    Location
    In an Amish Paradise
    Posts
    729
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    If it can't find any of the cases (make it true) then it will skip it...

    Try instead of yes and no true false, for now as a test...

    Also remember that a case is equal to a begin so don't forget to end the case.

    Hope this help,
    ~Stupedspam

  3. #3
    Join Date
    Mar 2007
    Location
    <3
    Posts
    2,683
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    True False ??
    I don't need that

    ( No offence :P ) Any1 expariance that can answer

  4. #4
    Join Date
    Dec 2006
    Location
    UK!!
    Posts
    910
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    im sure u didn't mean it but stupedspam is experienced,,, lol but i don't get your question please rephrase?

    ~Spaz

  5. #5
    Join Date
    Mar 2007
    Location
    <3
    Posts
    2,683
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Im trying to make a case that look what the string at settings says.

    So if PowerChop = Yes then it should begin MainLoopPower; but if i take it to yes it wont do MainLoopPower?

    And sorry for that havnt seen so much of you

    With hope - N1keee

  6. #6
    Join Date
    Dec 2007
    Posts
    103
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    You have stated that "incase 3 is 0, 1, or 2 then do something". And incase you didn't know, 3 is only 3 and cannot be 0, 1, or 2.

    Instead of setting PowerChop to a string set it to an integer and then do something like:
    SCAR Code:
    case PowerChop of
    0: WriteLn('Do something...'); //"Yes" could be replaced by 0
    1: WriteLn('Do something else...'); //Or by 1 - or 1 could be "no".
    2: WriteLn('Do something completely different...'); //Or "yes" or "no" could be 2!
    end;
    If you can follow my thoughts?
    This sentence is false.

  7. #7
    Join Date
    Apr 2007
    Posts
    3,152
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    SCAR Code:
    repeat
      if PowerChop = true then
      begin
        MainloopPower;
        break;
      end;
      if PowerChop = false then
      begin
        if Tr33Type = 1 then
        begin
          MainloopYew;
          end;
        end;
      end else
      begin
        If PowerChop = 'No' then
        begin
          if Tr33Type = 2 then
          begin
            MainloopWil;
            break;
          end;
      end;
      i := i + 1;
    until i := 3;
    im guessing that would work

    EDIT: wow yea case powerchop would work way better than mine
    EDIT EDIT: make ur yes and no's booleans so its true/false
    SCAR Tutorials: The Form Tutorial | Types, Arrays, and Classes
    Programming Projects: NotePad | Tetris | Chess


  8. #8
    Join Date
    Dec 2007
    Posts
    103
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Yeah, cases is much better in many cases, Dan (sorry had to do it! ).
    This sentence is false.

  9. #9
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Actually in your script, just take out the 0:, 1: and 2: and that would work as you wanted it to as there doesn't seem to be a need for cases in that snippet of script (cases are mainly used when you want to perform a random action, such as in an anti-ban).
    So the script would just be
    SCAR Code:
    if PowerChop = 'Yes' then
      MainloopPower
    else if PowerChop = 'No' then
      if Tr33Type = 1 then
        MainloopYew
    else if PowerChop = 'No' then
      if Tr33Type = 2 then
        MainloopWil;
    (only added some 'else's in to make it run slightly faster. Might also want to add a last 'else' in case the const's don't match any of those)
    Though Gumleren's method is just as applicable in this situation

  10. #10
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Like Gumleren said, just do this
    SCAR Code:
    case 3 of
     
     1: if PowerChop = 'Yes' then
        MainloopPower;
     2: if PowerChop = 'No' then
        if Tr33Type = 1 then
        MainloopYew;
     3: If PowerChop = 'No' then
        if Tr33Type = 2 then
        MainloopWil;
     end;
    You didn't have a 3 in there. Just 0, 1, and 2.

  11. #11
    Join Date
    May 2007
    Location
    baltimore, md
    Posts
    836
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    [scar]
    for i := 0 to 2 do
    case i of

    0: if PowerChop = 'Yes' then
    MainloopPower;
    1: if PowerChop = 'No' then
    if Tr33Type = 1 then
    MainloopYew;
    2: If PowerChop = 'No' then
    if Tr33Type = 2 then
    MainloopWil;
    end;

  12. #12
    Join Date
    Apr 2007
    Posts
    3,152
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    lol why is everyone posting more complicated stuff(including myself )

    case powerchop of would work the best because it has theleast amount of code. And bullzeye doesnt case start at 0?
    SCAR Tutorials: The Form Tutorial | Types, Arrays, and Classes
    Programming Projects: NotePad | Tetris | Chess


  13. #13
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by Dan Cardin View Post
    lol why is everyone posting more complicated stuff(including myself )

    case powerchop of would work the best because it has theleast amount of code. And bullzeye doesnt case start at 0?
    What? Case can be whatever you want it to be =/

  14. #14
    Join Date
    Dec 2007
    Posts
    103
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    But.. but!? Come on, people! Read the posts before you post (in this case, my post up there)!
    jhildys post can't be used because it goes through EVERY case (because of the for-loop). Bullzeyes post can't be used either because it only goes through the 3rd case (as 3 is always 3 and not 0, 1, or 2).
    Mixsters solution was actually good, but I still believe in cases - which also requires less code and is easier to read.
    This sentence is false.

  15. #15
    Join Date
    Aug 2007
    Posts
    1,404
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    Gumleren seems to be the only one with the right answer to the problem.

    I would do this:
    SCAR Code:
    case PowerChop of
       'Yes': MainloopPower;
       'No':
       begin
         case Tr33Type of
           1: MainloopYew;
           2: MainloopWil;
         end;
       end;
     end;

    -Knives

  16. #16
    Join Date
    Dec 2007
    Posts
    103
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Also a great solution, I'd say, Knives. Especially in this case where he wants to check Tr33Type too. I'd go for Knives' solution on this particular problem (and proberly many other problems too :P).
    This sentence is false.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Cases - how do I use them?
    By R0b0t1 in forum OSR Help
    Replies: 6
    Last Post: 08-30-2007, 02:37 PM
  2. Cases
    By EL_TYCHO in forum OSR Help
    Replies: 2
    Last Post: 06-26-2007, 11:30 AM
  3. Cases
    By inSaner in forum OSR Help
    Replies: 7
    Last Post: 05-06-2007, 04:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •