Results 1 to 8 of 8

Thread: Question with Case of

  1. #1
    Join Date
    Mar 2012
    Location
    127.0.0.1
    Posts
    1,199
    Mentioned
    0 Post(s)
    Quoted
    26 Post(s)

    Default Question with Case of

    I'm in the middle of writing my first script and I want to give people a choice of Teleports so I figured a case statement would be the easiest thing to use, however I am kind of confused on how that work.

    I want the user to be able to pick which area to teleport to in the Declare Players section
    Simba Code:
    Teleport := '' //Choose 0 (Edgeville), 1 (CastleWars), 2 (Fight Caves)

    This I think should work.

    However, how do I set up the case to work with this. I'm fairly certain this wont work even without having any of the teleport information in it.
    Simba Code:
    Procedure TeleporttoBank;  //Sets which bank to teleport to

    begin
      Case Teleport of
      0. Edgeville
      1. CastleWars
      2. FightCave
      end;
      if Case=0 then   // Edgeville Tele will require glory
        begin

        end else
      if Case=1 then   //CastleWars tele will require dueling ring
        begin

        end else
      if Case=2 then   //FightCave tele will require Tokkul-Zo ring (No need to get new ones)
        begin

        end else
        begin
        TerminateScript;
        end;
    end;

    E: I remember seeing a guide on Cases, but I couldn't find it when I did a search so if anyone knows where it went to, feel free to post a link!

    E2: Small change in code, but still essentially the same.
    Last edited by Hazzah; 06-05-2012 at 11:19 PM.

  2. #2
    Join Date
    May 2007
    Location
    England/Liverpool
    Posts
    1,004
    Mentioned
    9 Post(s)
    Quoted
    106 Post(s)

    Default

    lol misread

    Simba Code:
    Case Teleport of
      0: Edgeville; // you would call a function here that teleports you to edge for example
      1: CastleWars;
      2: FightCave;
      end;
    this is all you need
    so your user would have to pick a value fro 0-2 you can also do it as a string

    Simba Code:
    Case Teleport of
      'Edge': EdgeTelefunc; /
      'Cwars': Cwarstelefunc;
      Fcave: blabla;
      end;
    Last edited by Mark; 06-05-2012 at 11:31 PM.

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

    Default

    Or you can use the case to set vars (like coordinates, colors, etc.) and then use the set vars with a generic statement.

    EDIT: example case from my script:

    Simba Code:
    case Lowercase(Which) of
        'clan':
        begin
          Color := VexColor; Coords := [572, 291, 600, 318]; Clan := True;
          Area := 'clan grounds';
        end;
        'dung':
        begin
          Color := KinColor; Coords := [683, 371, 713, 386]; Clan := False;
          Area := 'daemonheim';
        end;
      end;

  4. #4
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default

    Simba Code:
    Procedure TeleporttoBank;  //Sets which bank to teleport to
    begin
      Case Teleport of
        0:
        Begin
          This;
          Is;
          Code to;
          Teleport to;
          Edeville;
        End;

        1:
        Begin
          This;
          Is;
          Code to;
          Teleport to;
          CastleWars;
        End;
        2:
        Begin
          This;
          Is;
          Code to;
          Teleport to;
          CastleWars;
        End;
      End;
    end;

    Liek dat.

  5. #5
    Join Date
    Mar 2012
    Location
    127.0.0.1
    Posts
    1,199
    Mentioned
    0 Post(s)
    Quoted
    26 Post(s)

    Default

    So something more like this?
    Simba Code:
    Procedure TeleporttoBank;  //Sets which bank to teleport to

    begin
      Case Teleport of
      0. Begin  // Edgeville Tele will require glory

         end;
      1. Begin //CastleWars tele will require dueling ring

         End;
      2. Begin //FightCave tele will require Tokkul-Zo ring (No need to get new ones)

         End;

      end else
      begin
        TerminateScript;
      end;
    end;

    E: I have to remember not to use periods :P

  6. #6
    Join Date
    Jan 2012
    Location
    Calgary, AB, Canada
    Posts
    1,819
    Mentioned
    5 Post(s)
    Quoted
    120 Post(s)

    Default

    More like this:

    Simba Code:
    procedure TeleportToBank;
    begin
      case Teleport of
        '0': //Must be in quotes as you're declaring it as a string
        begin
          // Edgeville Stuff here
        end;

        '1': // Without ending the case but the begin right under the zero
        begin
          // CastleWars here
        end;

        '2':
        begin
          // FightCave stuff here
        end;
      end;
    end;

    Edit: Some mad ninjaing just happened
    Current Project: Retired

  7. #7
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default

    Yup.
    You might want to add a
    Writeln('Please enter correct teleport location') before the termincatescript.

  8. #8
    Join Date
    Mar 2012
    Location
    127.0.0.1
    Posts
    1,199
    Mentioned
    0 Post(s)
    Quoted
    26 Post(s)

    Default

    Quote Originally Posted by YoHoJo View Post
    Yup.
    You might want to add a
    Writeln('Please enter correct teleport location') before the termincatescript.
    Thanks, I will do that. Hopefully I will finish it by the end of the week, but I think I might have bit off more than I could chew

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
  •