Bionicle
12-29-2009, 08:35 PM
Introduction
Well I got really bored today, and so I wrote this beginner tutorial, simply because I couldn't find many on this subject. Case's are extremely useful when scripting, they can make your script look neater and more professional, and they open up a few opportunities for things such as AntiBan.
What is a Case?
A case is in this format:
begin
Case {Integer, string or procedure} of
{Integer or string}: {what you want it to do}
{Second integer or string}: {what you want it to do}
{Third integer or string}: {what you want it to do}
//etc.
end;
end;
Integer Cases
Integer Cases are case statements that use integers for the different cases, as opposed to strings. These are more common, and you will see them in nearly every script in the AntiBan section. Here is an example:
program CaseExample;
var
i: Integer;
Procedure TheCase;
begin
Case i of
0: WriteLn('Case 1');
1: WriteLn('Case 2');
2: WriteLn('Case 3');
3: WriteLn('Case 4');
end;
end;
Procedure WriteTheCase;
begin
for i := 0 to 3 do
begin
TheCase;
Wait(300);
end;
end;
begin
WriteTheCase;
end.
If you don't know how the WriteTheCase procedure works, refer to my tutorial on loops. (http://www.villavu.com/forum/showthread.php?t=50774)
Now, copy this and pase it into scar. If you hit play, it will come out with this in the debug box:
Successfully compiled (78 ms)
Case 1
Case 2
Case 3
Case 4
Successfully executed
String Cases
String Cases are case statements that use strings for the different cases, as opposed to integers. These aren't as common, but you will see them from time to time. Here is an example of a simple one:
program CaseExample2;
const
WhichOne = 'Hello'; //Hello, World
procedure TheCase;
begin
Case WhichOne of
'Hello': begin
MoveMouse(179, 285);
Writeln('Hello Mouse is at 179, 285');
end;
'World': begin
MoveMouse(791, 760);
Writeln('World Mouse is at 791, 760');
end;
end;
end;
begin
TheCase;
end.
Cases With Procedures
These are more widly used, they are used with procedures that return something. For example, GetSkillLevel:
program CaseExample3;
{.include SRL/srl.scar} //we need to put this in this time because we're using an SRL procedure; GetSkillLevel
procedure GetTheLevel;
begin
case (GetSkillLevel('Mining')) of
1..14: Writeln('You can mine Clay, Copper and Tin.');
15..19: Writeln('You can mine Clay, Copper, Tin and Iron.');
20..29: Writeln('You can mine Clay, Copper, Tin, Iron and Silver.');
30..39: Writeln('You can mine Clay, Copper, Tin, Iron, Silver and Coal.');
40..54: Writeln('You can mine Clay, Copper, Tin, Iron, Silver, Coal and Gold.');
55..69: Writeln('You can mine Clay, Copper, Tin, Iron, Silver, Coal, Gold and Mithril.');
70..84: Writeln('You can mine Clay, Copper, Tin, Iron, Silver, Coal, Gold, Mithril and Adamantite.');
85..99: Writeln('You can mine Clay, Copper, Tin, Iron, Silver, Coal, Gold, Mithril, Adamantite and Rune.');
end;
end;
begin
GetTheLevel;
end.
This will get your current mining level, and then return the number. The number of your level will then trigger the case of that number, and use the case.
Random Cases
Random cases are most often found in AntiBan, they randomly choose a number between 0 and the number specified, then does that case. For example:
program CaseExample4;
procedure RandomMoveMouse;
begin
Case (Random(10)) of
0: MoveMouse(0, 0);
1: MoveMouse(10, 10);
2: MoveMouse(20, 20);
3: MoveMouse(30, 30);
4: MoveMouse(40, 40);
5: MoveMouse(50, 50);
6: MoveMouse(60, 60);
7: MoveMouse(70, 70);
8: MoveMouse(80, 80);
9: MoveMouse(90, 90);
end;
end;
begin
RandomMoveMouse;
end.
This will randomly choose one of the coordinates specified in the case, and move the mouse to it. Copy it into SCAR, you can play around with it, and then try making your own random case.
Calling Specific Cases
These are procedures made so that you call the integer of the case you want along with the procedure. Here is an example with writing random things:
procedure WriteRandomStuff(WhichToWrite: Integer); //So when you call it, you call it with the case you want to use
begin
case WhichToWrite of
1: Writeln('Write this!'); //if you call it WhichToWrite(1); then you will get this.
2: Writeln('We"re writing!'); //if you call it WhichToWrite(2); then you will get this.
3: Writeln('Write stuff!'); //etc...
4: Writeln('Aaaand writing!');
5: Writeln('This is fun.');
end;
end;
Conclusion
In conclusion, cases are very widely used, and if used properly, can be very beneficial. Any questions, comments, or corrections, don't hesitate to post below.
Well I got really bored today, and so I wrote this beginner tutorial, simply because I couldn't find many on this subject. Case's are extremely useful when scripting, they can make your script look neater and more professional, and they open up a few opportunities for things such as AntiBan.
What is a Case?
A case is in this format:
begin
Case {Integer, string or procedure} of
{Integer or string}: {what you want it to do}
{Second integer or string}: {what you want it to do}
{Third integer or string}: {what you want it to do}
//etc.
end;
end;
Integer Cases
Integer Cases are case statements that use integers for the different cases, as opposed to strings. These are more common, and you will see them in nearly every script in the AntiBan section. Here is an example:
program CaseExample;
var
i: Integer;
Procedure TheCase;
begin
Case i of
0: WriteLn('Case 1');
1: WriteLn('Case 2');
2: WriteLn('Case 3');
3: WriteLn('Case 4');
end;
end;
Procedure WriteTheCase;
begin
for i := 0 to 3 do
begin
TheCase;
Wait(300);
end;
end;
begin
WriteTheCase;
end.
If you don't know how the WriteTheCase procedure works, refer to my tutorial on loops. (http://www.villavu.com/forum/showthread.php?t=50774)
Now, copy this and pase it into scar. If you hit play, it will come out with this in the debug box:
Successfully compiled (78 ms)
Case 1
Case 2
Case 3
Case 4
Successfully executed
String Cases
String Cases are case statements that use strings for the different cases, as opposed to integers. These aren't as common, but you will see them from time to time. Here is an example of a simple one:
program CaseExample2;
const
WhichOne = 'Hello'; //Hello, World
procedure TheCase;
begin
Case WhichOne of
'Hello': begin
MoveMouse(179, 285);
Writeln('Hello Mouse is at 179, 285');
end;
'World': begin
MoveMouse(791, 760);
Writeln('World Mouse is at 791, 760');
end;
end;
end;
begin
TheCase;
end.
Cases With Procedures
These are more widly used, they are used with procedures that return something. For example, GetSkillLevel:
program CaseExample3;
{.include SRL/srl.scar} //we need to put this in this time because we're using an SRL procedure; GetSkillLevel
procedure GetTheLevel;
begin
case (GetSkillLevel('Mining')) of
1..14: Writeln('You can mine Clay, Copper and Tin.');
15..19: Writeln('You can mine Clay, Copper, Tin and Iron.');
20..29: Writeln('You can mine Clay, Copper, Tin, Iron and Silver.');
30..39: Writeln('You can mine Clay, Copper, Tin, Iron, Silver and Coal.');
40..54: Writeln('You can mine Clay, Copper, Tin, Iron, Silver, Coal and Gold.');
55..69: Writeln('You can mine Clay, Copper, Tin, Iron, Silver, Coal, Gold and Mithril.');
70..84: Writeln('You can mine Clay, Copper, Tin, Iron, Silver, Coal, Gold, Mithril and Adamantite.');
85..99: Writeln('You can mine Clay, Copper, Tin, Iron, Silver, Coal, Gold, Mithril, Adamantite and Rune.');
end;
end;
begin
GetTheLevel;
end.
This will get your current mining level, and then return the number. The number of your level will then trigger the case of that number, and use the case.
Random Cases
Random cases are most often found in AntiBan, they randomly choose a number between 0 and the number specified, then does that case. For example:
program CaseExample4;
procedure RandomMoveMouse;
begin
Case (Random(10)) of
0: MoveMouse(0, 0);
1: MoveMouse(10, 10);
2: MoveMouse(20, 20);
3: MoveMouse(30, 30);
4: MoveMouse(40, 40);
5: MoveMouse(50, 50);
6: MoveMouse(60, 60);
7: MoveMouse(70, 70);
8: MoveMouse(80, 80);
9: MoveMouse(90, 90);
end;
end;
begin
RandomMoveMouse;
end.
This will randomly choose one of the coordinates specified in the case, and move the mouse to it. Copy it into SCAR, you can play around with it, and then try making your own random case.
Calling Specific Cases
These are procedures made so that you call the integer of the case you want along with the procedure. Here is an example with writing random things:
procedure WriteRandomStuff(WhichToWrite: Integer); //So when you call it, you call it with the case you want to use
begin
case WhichToWrite of
1: Writeln('Write this!'); //if you call it WhichToWrite(1); then you will get this.
2: Writeln('We"re writing!'); //if you call it WhichToWrite(2); then you will get this.
3: Writeln('Write stuff!'); //etc...
4: Writeln('Aaaand writing!');
5: Writeln('This is fun.');
end;
end;
Conclusion
In conclusion, cases are very widely used, and if used properly, can be very beneficial. Any questions, comments, or corrections, don't hesitate to post below.