Results 1 to 5 of 5

Thread: turning an if then into a case

  1. #1
    Join Date
    May 2007
    Location
    in the forest
    Posts
    190
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default turning an if then into a case

    I'm trying to add an option to my script that the player can choose betwixt dropping the logs it chops or selling to the nearby general store

    SCAR Code:
    Players[0].Booleans[1]:=  true; //true sells logs, false drops

    //these are the two procedures I want to combine using a case.
    procedure CheckIfFull; //checks if inv is full if not it continues to choppa!
                                  //if its full it drops it using the dropper
    begin
    if Players[CurrentPlayer].Booleans[1]=false then
     begin

    if InvFull = true then
      begin
      writeln('full lets loose some weight');
       DropEmCowboy;
       LoadsDropped := (LoadsDropped + 1);
       ClearDebug;
       Writeln('Loads thus far = ' + inttostr(LoadsDropped));
       freedtm(WillowLog);

      end else
      writeln('not full lets cut more');
     end;
    end;

    Procedure SellInsteadOfDrop;
    Begin
      if Players[CurrentPlayer].Booleans[1]=true then
     Begin
     if InvFull = true then
      Begin
       WalkToStore;
       StoreAutoColor;
       WalkToStorePT2;
       WriteLn('store walked to');
       FreeDTM(WalkDTM);
      End else
       writeln('not full lets cut more');
     End;
    End;

    I was wondering if there is any suggestions on how to do this? I've been looking for a good tut on cases but I've yet to find one that doesnt use a randm case as an example
    At sea with the navy - not very active

  2. #2
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

    Default

    SCAR Code:
    procedure CheckIfFull; //checks if inv is full if not it continues to choppa!
                                  //if its full it drops it using the dropper
    begin
    if Players[CurrentPlayer].Booleans[1]=false then
     begin
     
    case Players[CurrentPlayer].Booleans[1] of
      true:begin
      writeln('full lets loose some weight');
       DropEmCowboy;
       LoadsDropped := (LoadsDropped + 1);
       ClearDebug;
       Writeln('Loads thus far = ' + inttostr(LoadsDropped));
       freedtm(WillowLog);
       end;
      false: writeln('not full lets cut more');
    end;
     end;
    end;

    ~shut

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

    Default

    SCAR Code:
    Case Players[CurrentPlayer].Booleans[1] Of
      True :  begin
     
    if InvFull = true then
      begin
      writeln('full lets loose some weight');
       DropEmCowboy;
       LoadsDropped := (LoadsDropped + 1);
       ClearDebug;
       Writeln('Loads thus far = ' + inttostr(LoadsDropped));
       freedtm(WillowLog);
     
      end else
      writeln('not full lets cut more');
     end;

      False :  Begin
     if InvFull = true then
      Begin
       WalkToStore;
       StoreAutoColor;
       WalkToStorePT2;
       WriteLn('store walked to');
       FreeDTM(WalkDTM);
      End else
       writeln('not full lets cut more');
     End;

    Rubbish standards btw

  4. #4
    Join Date
    May 2007
    Location
    in the forest
    Posts
    190
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    thanks

    Quote Originally Posted by NaumanAkhlaQ View Post
    Rubbish standards btw
    yeah I know Im working on that, should have seen them before...lol
    At sea with the navy - not very active

  5. #5
    Join Date
    May 2008
    Posts
    1,345
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    SCAR Code:
    Case Players[CurrentPlayer].Booleans[1] Of
      True : begin
               if InvFull = true then
               begin
                 writeln('full lets loose some weight');
                 DropEmCowboy;
                 LoadsDropped := (LoadsDropped + 1);
                 ClearDebug;
                 Writeln('Loads thus far = ' + inttostr(LoadsDropped));
                 freedtm(WillowLog);
               end else
               writeln('not full lets cut more');
             end;
      False : Begin
                if InvFull = true then
                Begin
                  WalkToStore;
                  StoreAutoColor;
                  WalkToStorePT2;
                  WriteLn('store walked to');
                  FreeDTM(WalkDTM);
                End else
                writeln('not full lets cut more');
              End;

    Just cuz I didn't like the look of it xD. Made it more readable, if not perfect.

    ~Sandstorm

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. comp turning off
    By Creth in forum OSR Help
    Replies: 17
    Last Post: 09-04-2007, 12:25 AM
  2. turning the mainscreen
    By legendaryhero90 in forum OSR Help
    Replies: 5
    Last Post: 02-21-2007, 12:38 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
  •