Results 1 to 10 of 10

Thread: case string of.... does that work? =S

  1. #1
    Join Date
    Dec 2006
    Location
    Canada, BC
    Posts
    728
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default case string of.... does that work? =S

    i seem to remember being able to do a case with strings before, but now its not working can anyone show me what im doing wrong?

    SCAR Code:
    procedure SetupVariables;
    begin
      case Variable[CurrentPlayer].KnifeType of
        'bronze': ChooseName := 'onze';
        'iron': ChooseName := 'ron';
        'steel': ChooseName := 'teel';
        'black': ChooseName := 'lack';
        'mithril': ChooseName := 'hril';
        'adamant': ChooseName := 'amant';
        'rune': ChooseName := 'une';
      end;
    end;
    Lance. Da. Pants.

  2. #2
    Join Date
    Nov 2007
    Location
    Chile
    Posts
    1,901
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Looks like you didn't set up KinfeType... Show where you declare them.


  3. #3
    Join Date
    Oct 2007
    Location
    http://ushort.us/oqmd65
    Posts
    2,605
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Should work, as a test do
    SCAR Code:
    procedure SetupVariables;
    var
      ChooseName ,me: string;
    begin
      me := 'rune';
      case me of
        'bronze': ChooseName := 'onze';
        'iron': ChooseName := 'ron';
        'steel': ChooseName := 'teel';
        'black': ChooseName := 'lack';
        'mithril': ChooseName := 'hril';
        'adamant': ChooseName := 'amant';
        'rune': ChooseName := 'une';
      end;
      writeln(ChooseName);
    end;
    I do visit every 2-6 months

  4. #4
    Join Date
    Oct 2006
    Location
    ithurtsithurtsithurtsithurts
    Posts
    2,930
    Mentioned
    7 Post(s)
    Quoted
    135 Post(s)

    Default

    Try changing this:
    SCAR Code:
    case Variable[CurrentPlayer].KnifeType of
    to this:
    SCAR Code:
    case Lowercase(Variable[CurrentPlayer].KnifeType) of

  5. #5
    Join Date
    Dec 2006
    Location
    Canada, BC
    Posts
    728
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    SCAR Code:
    type
      TVariable = Record
        FoodType, KnifeType : String;
        FightingStyle, Skill : Integer;
        PickupKnives : Boolean;
      end;

    var
      Variable : array of TVariable;
      ChooseName : String;

    procedure DeclarePlayers;
    begin
      HowManyPlayers := 1;
      NumberOfPlayers(HowManyPlayers);
      SetLength(Variable, HowManyPlayers);
      CurrentPlayer := 0;
     
      Players[0].Name :='';
      Players[0].Pass :='';
      Players[0].Nick :='';
      Players[0].Active := True;
      Variable[0].FoodType := 'lobster'; // Options: lobster, swordfish, monkfish, shark
      Variable[0].Skill := 4; //Options: attack: 0, defence: 1, strength: 2, ranged: 4
      Variable[0].FightingStyle := 1; // Fighting Style: 1, 2, 3, 4
      Variable[0].PickupKnives := True; // Pickup the Ranged wepons you used that are on the ground. If your melee set this to False
      Variable[0].KnifeType := 'iron'; // Options: Bronze, Iron, Steel, Black, Mithril, Adamant, Rune
    end;

    procedure SetupVariables;
    begin
      case Variable[CurrentPlayer].KnifeType of
        'bronze': ChooseName := 'onze';
        'iron': ChooseName := 'ron';
        'steel': ChooseName := 'teel';
        'black': ChooseName := 'lack';
        'mithril': ChooseName := 'hril';
        'adamant': ChooseName := 'amant';
        'rune': ChooseName := 'une';
      end;
    end;

    and i get this error: [Runtime Error] : Out Of Range in line 80 in script C:\Users\Lance\Desktop\My Scripting Projects\Reflection\Yak Pwner\Yak Pwner 0.1.scar

    it works while compiled but yeah, just when running it screws up.

    btw "case Variable[CurrentPlayer].KnifeType of" is line 80
    Last edited by Lance; 06-25-2009 at 08:23 AM.
    Lance. Da. Pants.

  6. #6
    Join Date
    Nov 2007
    Location
    Chile
    Posts
    1,901
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    You never call DeclarePlayers. Also look at senrath's suggestion.


  7. #7
    Join Date
    Jan 2007
    Location
    Nomming bits in your RAM
    Posts
    385
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Try doing
    writeln(inttostr(CurrentPlayer));
    before the case statement to see what you're getting.

    Also, remember to call DeclarePlayers; before SetUpVariables;
    Current Project: Catching up. XD. Potentially back for the summer, depending on how things go.

  8. #8
    Join Date
    Dec 2006
    Location
    Canada, BC
    Posts
    728
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    aggg i cant belive it was something so dumb as that. yup it was the declareplayers called after the SetupVariables.. thanks guys :P
    Lance. Da. Pants.

  9. #9
    Join Date
    Jan 2007
    Location
    Nomming bits in your RAM
    Posts
    385
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    You're welcome. ^_^

    (Is guilty of doing that MANY times in the past. )
    Current Project: Catching up. XD. Potentially back for the summer, depending on how things go.

  10. #10
    Join Date
    Oct 2006
    Location
    ithurtsithurtsithurtsithurts
    Posts
    2,930
    Mentioned
    7 Post(s)
    Quoted
    135 Post(s)

    Default

    Also, you should probably add in my suggestion as well. That way it doesn't matter if they write iron, Iron, IrOn, or any other form of capitalization.

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
  •