SRL Archive - OSR Help

3 way conditional loop?


wantonman

2012-05-14 21:55:45

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"…

tehq

2012-05-14 22:04:19

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.

Brandon

2012-05-14 22:10:22

No no.. don't use If-Else's like that..

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;

wantonman

2012-05-14 22:53:56

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

Brandon

2012-05-14 23:40:12

Remove the while loop. it will write just once.

wantonman

2012-05-16 19:40:20

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…



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.

Rich

2012-05-17 07:12:37

From: wantonman
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…



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.
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.