Ashur2Good
03-13-2008, 09:49 AM
Well, many people don't know what cases are. Which is a real shame, cause they are VERY useful.
Contents:
1. Introduction
I: Why should i learn this?
II: What will i learn after this?
III: What is a case?
2. Learning time
I: Basic procedure
II: Different types of cases
III: When to use cases
3. Ending
I: Final comments
II: Good bye's
Introduction
I: Why should i learn this?
Well, cases are a very important part in making good scripts. And everyone wants to make a good script...Right? Well, they are very useful in every way you use them, as you will see after :D
II: What will i learn after this?
At the end of this tutorial, you will learn how to use cases in both ways (Just wait and see!) and how to PROPERLY use them.
III: What is a case?
A case is a simple function that does whatever functions/procedures you tell it to do in order. But, the other way to use a case
is to make it choose a RANDOM function/procedure. Cases are effective in either way.
Learning time!
I: Basic procedure
Here is a basic procedure showing a case being used:
program Casez;
{.include SRL/SRL.scar}
var
x, y, i : integer;
procedure NormalCase;
begin
for i := 0 to 3 do //The i is just a normal integer, nothing special :P(Remember to include in var!)
case i of //with 4, it will only do the things you say to do from 0-3, Not 4!
1: Writeln('Ashurs cases tutorial!'); //You can use 0: as a case as well!
2: Writeln('You will learn how to use cases,');
3: Writeln('In both ways!');
end;
end;
procedure RandomCase;
begin
case random(4) of //Remember how 0 was included, it might randomly pick 0 and not do anything! :o
1: Writeln('Ashurs cases tutorial!');
2: Wait(20);
3: Mouse(x, y, 0, 0, true);
{4: WriteIn('It isnt very hard to do! GL!'); //This procedure will not be used! as it is in 4.
//That is why i have made it a comment :p }
end;
end;
begin
NormalCase;
RandomCase;
end.
Now, let's go into detail shall we.
procedure NormalCase;
begin
for i := 0 to 3 do //The i is just a normal integer, nothing special :P(Remember to include in var!)
case i of //with 4, it will only do the things you say to do from 0-3, Not 4!
1: Writeln('Ashurs cases tutorial!'); //You can use 0: as a case as well!
2: Writeln('You will learn how to use cases,');
3: Writeln('In both ways!');
end;
end;
Now, with a case we put it IN the procedure obviously :P
Next is the begin for the procedure. Now we are up to the case bit.
"case" will start the case bit. Then we will tell it that it will do everything from 1-3. Wow, now you're starting to get it, aren't you? :P
Then we write "of" :p. After that we start of with what we want it to do.
First thing is we want it to Writeln, then it will do all of those from 1-3. Simple? Yes!
If anyone has any questions about this part, just ask. ;)
Now, the next procedure is a RANDOM case, it do the same thing as the other procedure,
except RANDOMLY choose thing to do from the list of whatever you assign it to do. Now, the (4) Will be how many things you want it to go thru. BUT, the thing with that is for e.g.
If i choose (4) it will do a random thing i tell it from 0-3, NOT 4. So if it was 5 then it would be 0-5. Get it? Good.
So, if i choose "case RANDOM (2) of....0: Writein... 1: Mouse...."
It will pick a random one, so it will either Writeln one message, or the other message! But remember, it's all chance(random)!
II: Different types of cases
There are two diffrent types of cases (As mentioned before) Order or Random ones.
Here is a Order case:
procedure NormalCase;
begin
case (4) of //with 4, it will only do the things you say to do from 0-3, Not 4!
1: Writeln('Ashurs cases tutorial!'); //You can use 0: as a case as well!
2: Writeln('You will learn how to use cases,');
3: Writeln('In both ways!');
end;
And here is a random case:
procedure RandomCase;
begin
case random(4) of //Remember how 0 was included, it might randomly pick 0 and not do anything! :o
1: Writeln('Ashurs cases tutorial!');
2: Wait(20);
3: Mouse(x, y, 0, 0, true);
{4: WriteIn('It isnt very hard to do! GL!'); //This procedure will not be used! as it is in 4.
//That is why i have made it a comment :p }
end;
end;
III: When to use cases
You can use cases when you have a long list of things to do, OR when you need SCAR to randomly pick a function out of whatever choices you choose.
Ending
I: Final comments
Please reply with any rants/compliments and most importantly, Improvments!
II: Good Byes
Thanks for reading this, i hope your journey with SCAR improves from here, and i wish you luck on your ride.
P.S: I also attached the simple case script. For anyone that wants it :P
Cheers
-Ashur
Contents:
1. Introduction
I: Why should i learn this?
II: What will i learn after this?
III: What is a case?
2. Learning time
I: Basic procedure
II: Different types of cases
III: When to use cases
3. Ending
I: Final comments
II: Good bye's
Introduction
I: Why should i learn this?
Well, cases are a very important part in making good scripts. And everyone wants to make a good script...Right? Well, they are very useful in every way you use them, as you will see after :D
II: What will i learn after this?
At the end of this tutorial, you will learn how to use cases in both ways (Just wait and see!) and how to PROPERLY use them.
III: What is a case?
A case is a simple function that does whatever functions/procedures you tell it to do in order. But, the other way to use a case
is to make it choose a RANDOM function/procedure. Cases are effective in either way.
Learning time!
I: Basic procedure
Here is a basic procedure showing a case being used:
program Casez;
{.include SRL/SRL.scar}
var
x, y, i : integer;
procedure NormalCase;
begin
for i := 0 to 3 do //The i is just a normal integer, nothing special :P(Remember to include in var!)
case i of //with 4, it will only do the things you say to do from 0-3, Not 4!
1: Writeln('Ashurs cases tutorial!'); //You can use 0: as a case as well!
2: Writeln('You will learn how to use cases,');
3: Writeln('In both ways!');
end;
end;
procedure RandomCase;
begin
case random(4) of //Remember how 0 was included, it might randomly pick 0 and not do anything! :o
1: Writeln('Ashurs cases tutorial!');
2: Wait(20);
3: Mouse(x, y, 0, 0, true);
{4: WriteIn('It isnt very hard to do! GL!'); //This procedure will not be used! as it is in 4.
//That is why i have made it a comment :p }
end;
end;
begin
NormalCase;
RandomCase;
end.
Now, let's go into detail shall we.
procedure NormalCase;
begin
for i := 0 to 3 do //The i is just a normal integer, nothing special :P(Remember to include in var!)
case i of //with 4, it will only do the things you say to do from 0-3, Not 4!
1: Writeln('Ashurs cases tutorial!'); //You can use 0: as a case as well!
2: Writeln('You will learn how to use cases,');
3: Writeln('In both ways!');
end;
end;
Now, with a case we put it IN the procedure obviously :P
Next is the begin for the procedure. Now we are up to the case bit.
"case" will start the case bit. Then we will tell it that it will do everything from 1-3. Wow, now you're starting to get it, aren't you? :P
Then we write "of" :p. After that we start of with what we want it to do.
First thing is we want it to Writeln, then it will do all of those from 1-3. Simple? Yes!
If anyone has any questions about this part, just ask. ;)
Now, the next procedure is a RANDOM case, it do the same thing as the other procedure,
except RANDOMLY choose thing to do from the list of whatever you assign it to do. Now, the (4) Will be how many things you want it to go thru. BUT, the thing with that is for e.g.
If i choose (4) it will do a random thing i tell it from 0-3, NOT 4. So if it was 5 then it would be 0-5. Get it? Good.
So, if i choose "case RANDOM (2) of....0: Writein... 1: Mouse...."
It will pick a random one, so it will either Writeln one message, or the other message! But remember, it's all chance(random)!
II: Different types of cases
There are two diffrent types of cases (As mentioned before) Order or Random ones.
Here is a Order case:
procedure NormalCase;
begin
case (4) of //with 4, it will only do the things you say to do from 0-3, Not 4!
1: Writeln('Ashurs cases tutorial!'); //You can use 0: as a case as well!
2: Writeln('You will learn how to use cases,');
3: Writeln('In both ways!');
end;
And here is a random case:
procedure RandomCase;
begin
case random(4) of //Remember how 0 was included, it might randomly pick 0 and not do anything! :o
1: Writeln('Ashurs cases tutorial!');
2: Wait(20);
3: Mouse(x, y, 0, 0, true);
{4: WriteIn('It isnt very hard to do! GL!'); //This procedure will not be used! as it is in 4.
//That is why i have made it a comment :p }
end;
end;
III: When to use cases
You can use cases when you have a long list of things to do, OR when you need SCAR to randomly pick a function out of whatever choices you choose.
Ending
I: Final comments
Please reply with any rants/compliments and most importantly, Improvments!
II: Good Byes
Thanks for reading this, i hope your journey with SCAR improves from here, and i wish you luck on your ride.
P.S: I also attached the simple case script. For anyone that wants it :P
Cheers
-Ashur