SRL Archive - OSR Help

Cases


xdarkshadowx

2012-12-26 23:24:09

If I have a case, and I want it to do something if it doesn't run into the integers I gave it, how do I catch everything else?

riwu

2012-12-26 23:28:38

Have an else statement after the cases. It will be executed if the value doesn't meet any of the cases.

xdarkshadowx

2012-12-26 23:38:11

mmk, like such?

case findLocation(0) of
0: begin
Lave;
wait(25000 + random(5000));
end;
1: begin
inventory;
end;
else: begin
functionOrWhatNotHere();
end;
end;



would that work? or did I misunderstand the syntax?

Gucci

2012-12-26 23:39:09

Basically:

procedure Something;
begin
case something of
//case stuff
end else //The stuff to do if it doesn't solve the case
end;

riwu

2012-12-27 00:47:32

From: Gucci
Basically:

procedure Something;
begin
case something of
//case stuff
end else //The stuff to do if it doesn't solve the case
end;

It should be encased within the case statement.


From: xdarkshadowx
mmk, like such?

case findLocation(0) of
0: begin
Lave;
wait(25000 + random(5000));
end;
1: begin
inventory;
end;
else: begin
functionOrWhatNotHere();
end;
end;



would that work? or did I misunderstand the syntax?


case findLocation(0) of
0:
begin
Lave;
wait(25000 + random(5000));
end;

1:
inventory; //begin and end not needed if it's single statement

else // ':' is not required after 'else', 'then' etc in Pascal (needed in some other languages such as Python though)
functionOrWhatNotHere();
end;

Gucci

2012-12-27 00:49:47

From: riwu
It should be encased within the case statement.


Should work fine there

riwu

2012-12-27 01:16:56

From: Gucci
Should work fine there

Would result in an syntax error.
You can think case statements as multiple statements of 'else if',
From: Gucci
Basically:

procedure Something;
begin
case something of
//case stuff
end else //The stuff to do if it doesn't solve the case
end;

Hence the 'end else' here would be like directed at the 'case something of' instead of those 'else if' statements within the case construct ;)

Gucci

2012-12-27 01:18:32

From: riwu
Would result in an syntax error.
You can think case statements as multiple statements of 'else if',

Hence the 'end else' here would be like directed at the 'case something of' instead of those 'else if' statements within the case construct ;)


Hmmmm didn't think of it that way ;)