SRL Archive - OSR Help

Question with Case of


Hazzah

2012-06-05 19:12:36

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

Mark

2012-06-05 19:21:23

lol misread

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

Case Teleport of
'Edge': EdgeTelefunc; /
'Cwars': Cwarstelefunc;
Fcave: blabla;
end;

Runaway

2012-06-05 19:23:12

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:


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;

YoHoJo

2012-06-05 19:24:01

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.

Hazzah

2012-06-05 19:25:23

So something more like this?
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

Gucci

2012-06-05 19:25:44

More like this:

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 :o

YoHoJo

2012-06-05 19:26:14

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

Hazzah

2012-06-05 19:35:40

From: YoHoJo
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 :duh: