SRL Archive - Outdated Tutorials

Cases, and how to use them!


dudesareus

2007-05-02 20:15:36

Hey, it's me dudesareus here, and I'm going to teach you how to use cases. I have been looking around for the past couple days for some good tutorials that focus mainly on cases. So thanks for reading and hope I taught you something!


Part 1

When your using a Case, you don't need a begin, just an end, which is pretty cool. Cases can be used in many things such as Anti-Ban, and Fail-Safes.

Part 2

The first thing you need to know is how to use them.

Case Random(3) of
end;
In between the Case and the end, you would do something like this;

Case Random(3) of
0: MakeCompass('S');
1: MakeCompass('E');
2: MakeCompass('W');
end;
If you noticed above you start with a 0 and not a 1. You can use something else than MakeCompass like MouseBox.

Part 3

Lets say you want a procedure to use as a Case random, if you would like to do something like that you would do this;

Procedure DoSomething1;
begin
DoSomething;
end;

Procedure DoSomething2;
begin
DoSomething;
end;

Procedure CaseInThisProcedure;
begin
RadialWalk(FindRoadColor,1,1,70 etc. etc.);
Case Random(2) of
0: DoSomething1;
1: DoSomething2;
end;
end;

I hope you liked this brief tutorial on Cases, I may update when I have more time! If you would like more info on Fail-Safes and Anti-Ban then just search around the forums for them.

EDIT: I added a little script that shows how its used, I used Writeln and if you look through the entire debug box after you can see that all of the Writeln's are random and not all used the same.

bullzeye95

2007-05-02 20:20:48

I'd also like to add that you can use cases like this
case Random(50) of
1,3: DoSomething;
10: DoSomethingElse;
else
DoAnotherThing;
end;

dudesareus

2007-05-02 20:24:35

Oops, yeah sorry bout that :p

seungki

2007-05-22 06:38:34

From: bullzeye95
I'd also like to add that you can use cases like this
case Random(50) of
1,3: DoSomething;
10: DoSomethingElse;
else
DoAnotherThing;
end;


Sorry for gravedigging, and maybe I should have pmed you this question. However, does that syntax mean that if case chose a random number of 1-3, then it will do the procedure DoSomething (I'm not sure if it's 1-3 or 1&3).

And….if case is 10, it will do the procedure DoSomethingElse…and if case is none of the above, it will do the proccedure DoAnotherThing. Correct?

Also, does SCAR not include a 0 when you do random(int)? Say if I said Random(3); would I get in turn a result of 0,1,2,3 or 1,2,3?

Thanks.
-seungki

Janilabo

2007-05-22 07:19:21

From: seungki
Sorry for gravedigging, and maybe I should have pmed you this question. However, does that syntax mean that if case chose a random number of 1-3, then it will do the procedure DoSomething (I'm not sure if it's 1-3 or 1&3).
Just if it's number 1 or 3 ;) Not between.

From: seungki
And….if case is 10, it will do the procedure DoSomethingElse…and if case is none of the above, it will do the proccedure DoAnotherThing. Correct?
Correct :)

From: seungki
Also, does SCAR not include a 0 when you do random(int)? Say if I said Random(3); would I get in turn a result of 0,1,2,3 or 1,2,3?
Random(3) would result to 0,1,2.. If you do Random(3) + 1 it would result to 1,2,3 and if you do Random(3 + 1) [or just enter 4] then it would result to 0,1,2,3

Hopefully that helps Seungki :)

Robbiej

2007-05-22 10:38:42

How about when i use…
case GetSkillLevel('woodcutting') of
1..14: TreeToCut:= 'Tree';
15..29: TreeToCut:= 'Oak';

etc.?

so when woodcutting level is 1-14, threetocut is tree etc.

Lalaji

2007-05-22 10:52:15

Nice dude, that helped me out!

seungki

2007-05-22 19:59:29

Ah, I see.

Thanks again,
Seungki

dark4mdawn

2007-08-18 17:09:10

kol been loking for tut on this 4 a while