Results 1 to 7 of 7

Thread: 3 way conditional loop?

  1. #1
    Join Date
    Sep 2010
    Location
    Azeroth
    Posts
    395
    Mentioned
    0 Post(s)
    Quoted
    17 Post(s)

    Exclamation 3 way conditional loop?

    im making a script rpg and im in need of help... im in a problem with this loop...
    ill explain it to the best of my knowledge... here it is...

    "okay so i have 3 areas to walk around area1 area2 area3... whichever area i move into (lets say area1 is x:=0, area2 is x:=1, area3 is x:=2) i would like to have a message displayed whenever i enter a new area ((writeln('you are now in area 1 2 or 3 ~)))"

    the problem is i am having trouble telling simba how to calculate a system that counts and results into a solution... my trouble is that "it counts area1 and area2 but when i move back to area1 from area2 it does not work"...

  2. #2
    Join Date
    Nov 2011
    Location
    MA
    Posts
    545
    Mentioned
    3 Post(s)
    Quoted
    10 Post(s)

    Default

    If (function to see if you are in area1) then
    Area:=1 else
    if (..area2) then
    Area:=2 else
    If (..area3) then
    Area:=3 else
    If not (area1) and not (area2) and not (area3) then
    Begin
    Writeln('Not in any of the areas');
    Area:=0;
    End;


    Bear in mind this is a very rough outline because i'm on my mobile. I'll help tomorrow if no one else does.

  3. #3
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    No no.. don't use If-Else's like that..
    Simba Code:
    GetOurArea;
    While (Area) do
    begin
      Case Area of
            1:  writeln('In Area 1');

            2:  writeln('In Area 2');

            3:  writeln('In Area 3');

          else
            writeln('In Unknown Area');
      end;
      GetOurArea;
    end;
    I am Ggzz..
    Hackintosher

  4. #4
    Join Date
    Sep 2010
    Location
    Azeroth
    Posts
    395
    Mentioned
    0 Post(s)
    Quoted
    17 Post(s)

    Default

    Ggzz how would i get it to just writeln one time instead of it keep repeating whilst in an area?

  5. #5
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Remove the while loop. it will write just once.
    I am Ggzz..
    Hackintosher

  6. #6
    Join Date
    Sep 2010
    Location
    Azeroth
    Posts
    395
    Mentioned
    0 Post(s)
    Quoted
    17 Post(s)

    Default

    i know this is a late response but bare with me

    okay here is an example script for my rpg and it should help incorporate the case statement...


    Simba Code:
    program new;

    var
      x:integer;
      c:boolean;







    procedure in_area;
     begin
      while c=true do
       begin
        if x=1 then
         begin
           writeln('in area 1');
             end
              else
               if x=2 then
                begin
                  writeln('in area 2');
                    end
                     else
                      if x=3 then
                       begin
                         writeln('in area 3');
                           end;
                             break;
                               end;
                                end;





    procedure movement;

    begin

    if iskeydown(38) then

    begin
      x:=(x+1);
      writeln(x);
      wait(500);
        end;

        if IsKeyDown(40) then

        begin
          x:=(x-1);
          writeln(x);
          wait(500);
            end;

            end;




    procedure main;

    begin
    c:=true
    x:=1
    repeat
      movement;
      in_area;
        until (false);

          end;



    begin
    main;
    end.

  7. #7
    Join Date
    May 2007
    Location
    England
    Posts
    4,140
    Mentioned
    11 Post(s)
    Quoted
    266 Post(s)

    Default

    Quote Originally Posted by wantonman View Post
    i know this is a late response but bare with me

    okay here is an example script for my rpg and it should help incorporate the case statement...


    Simba Code:
    program new;

    var
      x:integer;
      c:boolean;







    procedure in_area;
     begin
      while c=true do
       begin
        if x=1 then
         begin
           writeln('in area 1');
             end
              else
               if x=2 then
                begin
                  writeln('in area 2');
                    end
                     else
                      if x=3 then
                       begin
                         writeln('in area 3');
                           end;
                             break;
                               end;
                                end;





    procedure movement;

    begin

    if iskeydown(38) then

    begin
      x:=(x+1);
      writeln(x);
      wait(500);
        end;

        if IsKeyDown(40) then

        begin
          x:=(x-1);
          writeln(x);
          wait(500);
            end;

            end;




    procedure main;

    begin
    c:=true
    x:=1
    repeat
      movement;
      in_area;
        until (false);

          end;



    begin
    main;
    end.
    Simba Code:
    program New;

    var
      X : Integer;
      C : Boolean;

    procedure In_Area;
    begin
      case X of
        1 : WriteLn('In area 1');
        2 : WriteLn('In area 2');
        3 : WriteLn('In area 3');
     end;
    end;

    procedure Movement;
    begin
      if IsKeyDown(38) then
      begin
        if (X = 3) then
        begin
          WriteLn('X can''t be higher than 3');
          Exit;
        end;
        X:= (X + 1);
        WriteLn(X);
        Wait(500);
      end;
      if IsKeyDown(40) then
      begin
        if (X = 1) then
        begin
          WriteLn('X can''t be lower than one');
          Exit;
        end;
        X:=(X - 1);
        WriteLn(X);
        Wait(500);
      end;
    end;

    procedure Main;
    begin
      C:= True;
      X:= 1
      repeat
        Movement;
        In_Area;
      until(False);
    end;

    begin
      Main;
    end.
    I used a case for the In_Area procedure, neatened it up a bit, and also made it so that X can't increase when already 3 or decrease when 1.
    <3

    Quote Originally Posted by Eminem
    I don't care if you're black, white, straight, bisexual, gay, lesbian, short, tall, fat, skinny, rich or poor. If you're nice to me, I'll be nice to you. Simple as that.

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
  •