mastaraymond
2007-09-14 04:23:16
Hello,
This tut is going about some procedures you may not know. It contains some random things, but i think you would like to know it ;). Lets start i guess?
Table of index:
Slow functions
–Inc\Dec
–Length
Random things
–clColors
–Continue
–Chr
–Integer as Procedure
–Const as a parameter
Compiler directives
–List of commands
–Example
Unusual functions
–Xor
–SHR and SHL
–And,or,Xor,Not as math functions
–Hex
API Calls
–Explanation
GetSelf and GetApplication
–List of commands
–Example
Types
–Type list
–Example of using procedures in types
Slow functions
In this version, scar 11, there are some functions that are slower then others ^^.
Inc\Dec(x : integer): This like 2 times slower than x := x +\- 1;
Length(Arr : Array); If you use Length for getting the length of an array, you should use GetArrayLength. Length is just a bit slower but every ms counts ^^.
Random things
clColors
Most of you know it already, for those who don't: SCAR has got a big library of already set 'Consts'. You have got consts for RuneScape, like: MSX1, MSCX etc.. But there are also a lot of COLORS defined! For example, if you need black you can just type : clBlack. Its the defined const for 0. You have got loads of these. Try this: Type cl + ctrl + space in scar, you see a huge list of colors popping up ;).
Continue
This command has been posted somewhere else on the forum, but for those who dont know. The continue command goes back to the begin of a loop, its like a 'Goto' command, but without defining the label, its really useful. Here is a example:
Chr(x : Byte)
You can replace Chr(63) by #63 . Its a lot shorter to write, here is a example.
Integer as procedure!
Did you know, you can use some types as a procedure to? I've done a few tries and heres a example:
Const in parameters?
This is kinda useless:spot:. If you make a procedure can user parameters like (var I : string;B : integer). But did you know you can add 'const' to it? It would become like this: Procedure test ( const s : string);. Not really useful or so, but just cool to know ^^.
Compiler directives
SCAR has got a few compiler directives, they aren't very useful, but cool ^^.
A compiler directive is something that communicates with the compiler himself, its a piece of code that tells the compiler to do, or not do something.
As far as i know, scar only supports 'if' statements in the directives. Lets take a look at the directives, how to use them is bellow:
$Define: This declares something, like setting a boolean to true.
$UnDef: This UNdeclares something, like setting a boolean to false.
$IfDef: This is a IF loop, if the thing that comes behind this statement is defined then…
$IfOpt: Im not sure, i think its the same as $IfDef.
$IfNDef: If something is NOT defined then..
$Else: Just like if .. else.
$EndIf: You must place this after a if loop, to show the compiler your done with the loop!
Here is a example with using the most directives:
Look in the test folder, copied it for you:
Unusual functions
Xor
You guys all know keywords like or, not , and. There is a forth, called Xor. Xor checks if only 1 side of the statement is true. If only 1 side returns true, the xor command returns true. Here an example:
SHR and SHL
(For more info about this I like to refer to yakmans_ tutorial about bitwise operations)
My brabble below is wrong, It's not exactly what the function does. Do not take it for granted.
First of all i want to thank Wizzup? For explaining this to me :rolleyes:.
SHL and SHR are functions that shift bits, of the binary of a integer, if im right ^^. Its kinda easy: 2 shl 10 = 2048. Other written its: 2 x 2^10. Another example, 5 shl 4 = 80. Other written its: 5 x 2^4. SHR is kinda the same, except it divides the integer. 1 shr 2048 = 1. Other written it would be: 1024 div 2^10. Im not quite sure how shr really works, but google it if you really want to know^^. Im not good at explaining this, so heres a example:
And, Or, Xor, Not as math functions!
You know the keywords above, but did you know they can be used as math functions to? And, Or, Xor and Not can be used as math functions on integers. It compars the binary of the numbers you put in, and results something 'new'. Below a explanation of what they do, those numbers are binary.
Xor | 10110001 Xor 01100110 = 11010111. If the bits are equal, the result bit becomes a 0 else a 1.
Or | 10110001 Or 01100110 = 11110111. If both bits are 0, the result becomes a 0 else a 1.
And | 10110001 And 01100110 = 00100000. If both bits are 1, the result bit becomes a 1 else a 0.
Not | Not reverses the input, the 0 becomes a 1 and a 1 becomes a 0.
Hex!
Hex (Hexadecimal) is a different numeral system that we are used to. Hex is a 16-base numeral system, while we are used to the decimal system (10-Base).
Heres a comparing:
Decimals: [0,1,2,3,4,5,6,7,8,9]
Hex: [0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F]
The decimal number 10 in hex is A, 11 is B etc.. Hex is often used for HTML, as a color. Its a quite simple system. Colors are based on a R,G,B value. The max of each value is 255. In hex FF is equal to 255, this means you can declare R,G,B by using max 2 digits per color. The HTML hex colors are like this
#RRGGBB. The first 2 digits represent the red value, the GG green and BB blue.
So, #FFFFFF : R = 255, G = 255, B = 255. In scar to use a Hex number you need to put a $ in front of it. $F = 15. I've made IntToHex and HexToInt, its somewhere in the snippet board.
API calls
A API call is basically calling procedures out of other files. Windows has made a lot of DLLs, this are files which contain procedures and functions that edit or do something in windows. API Calls allow us to call those functions and use them. If you want to do a API Call you must enable 'API Calls' in the Script tab of SCAR. Then use the syntax below to load the procedure into scar, and then just use it ^^. For more info check the DLLTest.Scar in your Script>Test folder!
function FindWindow(C1, C2: PChar): Longint; external 'FindWindowA@user32.dll stdcall' ;
GetSelf and GetApplication
I think most of you know GetSelf and GetApplication, but for those who don't ;). This 2 commands are objects, that belong the scar itself. Ill give you a short list of useful commands:
GetSelf.Caption : This changes the title of the scar window, you can also do this by Disguise(Title : string);
GetSelf.Enabled : This is a nasty command. If you set this command to false you can Disable scar, which means you cant press buttons or change the windows position, its like freezing scar.
GetSelf.Handle : This is the HWND handle of scar. Every window has got a handle, with this handle you can change the windows size, move it, change title its often used in
GetSelf.Height\Width : This are commands which indicate the size of the scar window.
GetSelf.Left\Top : This are the x and y of the left top from scar. If you change these, scar will move.
GetSelf.Hide\Show : This .Hide hides the scar window until you have called .show . When the window is hidden, i dont think there is a way to get it back, without using GetSelf.Show.
GetSelf.Visible : This is almost the same as show\hide. Once you made it invisible, you must set the boolean to true to get it back!
GetSelf.WindowState : This is the state of the window, in scar can give it 3 states: Minimized, Maximized and Normal. Use it like this: GetSelf.WindowState := wsMaximized;
GetApplication.Minimize : With this procedure you can minimize the scar window.
GetApplication.Handle : Also indicates a handle, I dont know exactly what the difference with GetSelf.Handle is, i guess the getself is a ChildForm handle..
GetApplication.MessageBox : This is a cool feature, it allows you to show MessageBoxes to the user, with for defined boxes. The first parameters is what text you want to show, the second what title the box should have and the 3th indicates what kind of box you want to have. I made a example.
Ok, i guess we all know Types, if not read Nielsies tutorial. Types in scar are quite limited but we can still do some cool stuff. A type doesn't have to be a RECORD. I made some examples of types i know:
Temp = Array of array of array of integer; This one makes a type that has got 3 dimensions.
Temp = (True,False,Maybe); This one makes a type that can hold 3 values: True,False, Maybe. When you load this type, its declared as True by default, because True is the first on in the list :p. If you make it: (False,True,Maybe) Its loads False by default.
Temp = record x,y : integer end; This one makes a type that can hold the values x and y.
Temp = Function ( X : integer) : string; This one makes a type for a function. This is cool, its like a pointer to a procedure. It also allows you to use a function as a parameter. Its hard to explain this, so thats why i added a example script! Look and understand ;).
This tut is going about some procedures you may not know. It contains some random things, but i think you would like to know it ;). Lets start i guess?
Table of index:
Slow functions
–Inc\Dec
–Length
Random things
–clColors
–Continue
–Chr
–Integer as Procedure
–Const as a parameter
Compiler directives
–List of commands
–Example
Unusual functions
–Xor
–SHR and SHL
–And,or,Xor,Not as math functions
–Hex
API Calls
–Explanation
GetSelf and GetApplication
–List of commands
–Example
Types
–Type list
–Example of using procedures in types
Slow functions
In this version, scar 11, there are some functions that are slower then others ^^.
Inc\Dec(x : integer): This like 2 times slower than x := x +\- 1;
Length(Arr : Array); If you use Length for getting the length of an array, you should use GetArrayLength. Length is just a bit slower but every ms counts ^^.
Random things
clColors
Most of you know it already, for those who don't: SCAR has got a big library of already set 'Consts'. You have got consts for RuneScape, like: MSX1, MSCX etc.. But there are also a lot of COLORS defined! For example, if you need black you can just type : clBlack. Its the defined const for 0. You have got loads of these. Try this: Type cl + ctrl + space in scar, you see a huge list of colors popping up ;).
Continue
This command has been posted somewhere else on the forum, but for those who dont know. The continue command goes back to the begin of a loop, its like a 'Goto' command, but without defining the label, its really useful. Here is a example:
program New;
begin
Repeat
Writeln('Before continue!');
Continue;
Writeln('After continue!');
Until(false)
end.program New;
var
I : integer;
begin
For I:= 0 to 15 do
begin;
if (I = 5) or (I = 14) then Continue;
Writeln('The number is: '+inttostr(I));
end;
end.Chr(x : Byte)
You can replace Chr(63) by #63 . Its a lot shorter to write, here is a example.
program New;
begin
Writeln(chr(72)+chr(101)+chr(108)+chr(108)+chr(111)+chr(32)+chr(119)+chr(111)+chr(114)+chr(108)+chr(100));
Writeln(#72#101#108#108#111#32#119#111#114#108#100);
end.Integer as procedure!
Did you know, you can use some types as a procedure to? I've done a few tries and heres a example:
program New;
var
C : integer;
D : Char;
begin
C := Integer(5);
D := Char('A');
Writeln(Inttostr(C));
Writeln(D);
end.Const in parameters?
This is kinda useless:spot:. If you make a procedure can user parameters like (var I : string;B : integer). But did you know you can add 'const' to it? It would become like this: Procedure test ( const s : string);. Not really useful or so, but just cool to know ^^.
Compiler directives
SCAR has got a few compiler directives, they aren't very useful, but cool ^^.
A compiler directive is something that communicates with the compiler himself, its a piece of code that tells the compiler to do, or not do something.
As far as i know, scar only supports 'if' statements in the directives. Lets take a look at the directives, how to use them is bellow:
$Define: This declares something, like setting a boolean to true.
$UnDef: This UNdeclares something, like setting a boolean to false.
$IfDef: This is a IF loop, if the thing that comes behind this statement is defined then…
$IfOpt: Im not sure, i think its the same as $IfDef.
$IfNDef: If something is NOT defined then..
$Else: Just like if .. else.
$EndIf: You must place this after a if loop, to show the compiler your done with the loop!
Here is a example with using the most directives:
program New;
{$Define Bla}
begin
{$IfDef bla}
WritelN('Defined!');
{$endif}
{$IFNDef bla}
Writeln('We didnt Define it!');
{$endIf}
{$UnDef bla}
{$IfDef bla}
WritelN('Defined!');
{$else}
WritelN('Not defined!');
{$endIf}
end. Also scar has got 1 defined directive if im right: divi.Look in the test folder, copied it for you:
program DiviDirective;
begin
{$IfDef Divi}
WriteLn('This is SCAR Divi 3.05 or higher!');
{$Else}
WriteLn('This is SCAr Divi 3.04 or lower!');
{$EndIf}
end.Unusual functions
Xor
You guys all know keywords like or, not , and. There is a forth, called Xor. Xor checks if only 1 side of the statement is true. If only 1 side returns true, the xor command returns true. Here an example:
program New;
begin
if (50 = 50) xor (50=40) then Writeln('Only 1 side returns true!');
if (50=50) xor (50=50) then
Writeln('Both sides return true!')
else
Writeln('Both sides return true, or both sides return false!');
end.SHR and SHL
(For more info about this I like to refer to yakmans_ tutorial about bitwise operations)
My brabble below is wrong, It's not exactly what the function does. Do not take it for granted.
First of all i want to thank Wizzup? For explaining this to me :rolleyes:.
SHL and SHR are functions that shift bits, of the binary of a integer, if im right ^^. Its kinda easy: 2 shl 10 = 2048. Other written its: 2 x 2^10. Another example, 5 shl 4 = 80. Other written its: 5 x 2^4. SHR is kinda the same, except it divides the integer. 1 shr 2048 = 1. Other written it would be: 1024 div 2^10. Im not quite sure how shr really works, but google it if you really want to know^^. Im not good at explaining this, so heres a example:
program New;
begin
Writeln(inttostr( 1 shl 10));
Writeln(inttostr( 1 shr 1024));
Writeln(FloatTostr(pow(2,10)));
Writeln(FloatToStr(1024 div Pow(2,10)));
end.And, Or, Xor, Not as math functions!
You know the keywords above, but did you know they can be used as math functions to? And, Or, Xor and Not can be used as math functions on integers. It compars the binary of the numbers you put in, and results something 'new'. Below a explanation of what they do, those numbers are binary.
Xor | 10110001 Xor 01100110 = 11010111. If the bits are equal, the result bit becomes a 0 else a 1.
Or | 10110001 Or 01100110 = 11110111. If both bits are 0, the result becomes a 0 else a 1.
And | 10110001 And 01100110 = 00100000. If both bits are 1, the result bit becomes a 1 else a 0.
Not | Not reverses the input, the 0 becomes a 1 and a 1 becomes a 0.
Hex!
Hex (Hexadecimal) is a different numeral system that we are used to. Hex is a 16-base numeral system, while we are used to the decimal system (10-Base).
Heres a comparing:
Decimals: [0,1,2,3,4,5,6,7,8,9]
Hex: [0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F]
The decimal number 10 in hex is A, 11 is B etc.. Hex is often used for HTML, as a color. Its a quite simple system. Colors are based on a R,G,B value. The max of each value is 255. In hex FF is equal to 255, this means you can declare R,G,B by using max 2 digits per color. The HTML hex colors are like this
#RRGGBB. The first 2 digits represent the red value, the GG green and BB blue.
So, #FFFFFF : R = 255, G = 255, B = 255. In scar to use a Hex number you need to put a $ in front of it. $F = 15. I've made IntToHex and HexToInt, its somewhere in the snippet board.
API calls
A API call is basically calling procedures out of other files. Windows has made a lot of DLLs, this are files which contain procedures and functions that edit or do something in windows. API Calls allow us to call those functions and use them. If you want to do a API Call you must enable 'API Calls' in the Script tab of SCAR. Then use the syntax below to load the procedure into scar, and then just use it ^^. For more info check the DLLTest.Scar in your Script>Test folder!
function FindWindow(C1, C2: PChar): Longint; external 'FindWindowA@user32.dll stdcall' ;
GetSelf and GetApplication
I think most of you know GetSelf and GetApplication, but for those who don't ;). This 2 commands are objects, that belong the scar itself. Ill give you a short list of useful commands:
GetSelf.Caption : This changes the title of the scar window, you can also do this by Disguise(Title : string);
GetSelf.Enabled : This is a nasty command. If you set this command to false you can Disable scar, which means you cant press buttons or change the windows position, its like freezing scar.
GetSelf.Handle : This is the HWND handle of scar. Every window has got a handle, with this handle you can change the windows size, move it, change title its often used in
GetSelf.Height\Width : This are commands which indicate the size of the scar window.
GetSelf.Left\Top : This are the x and y of the left top from scar. If you change these, scar will move.
GetSelf.Hide\Show : This .Hide hides the scar window until you have called .show . When the window is hidden, i dont think there is a way to get it back, without using GetSelf.Show.
GetSelf.Visible : This is almost the same as show\hide. Once you made it invisible, you must set the boolean to true to get it back!
GetSelf.WindowState : This is the state of the window, in scar can give it 3 states: Minimized, Maximized and Normal. Use it like this: GetSelf.WindowState := wsMaximized;
GetApplication.Minimize : With this procedure you can minimize the scar window.
GetApplication.Handle : Also indicates a handle, I dont know exactly what the difference with GetSelf.Handle is, i guess the getself is a ChildForm handle..
GetApplication.MessageBox : This is a cool feature, it allows you to show MessageBoxes to the user, with for defined boxes. The first parameters is what text you want to show, the second what title the box should have and the 3th indicates what kind of box you want to have. I made a example.
program New;
var
I : integer;
begin
I := GetApplication.MessageBox('You want to writeln Hello world?','Question',4);
if I = 6 then Writeln('Hello World');
if I = 7 then Writeln('You basterd, why you dont want to write Hello World?');
end.TypesOk, i guess we all know Types, if not read Nielsies tutorial. Types in scar are quite limited but we can still do some cool stuff. A type doesn't have to be a RECORD. I made some examples of types i know:
Temp = Array of array of array of integer; This one makes a type that has got 3 dimensions.
Temp = (True,False,Maybe); This one makes a type that can hold 3 values: True,False, Maybe. When you load this type, its declared as True by default, because True is the first on in the list :p. If you make it: (False,True,Maybe) Its loads False by default.
Temp = record x,y : integer end; This one makes a type that can hold the values x and y.
Temp = Function ( X : integer) : string; This one makes a type for a function. This is cool, its like a pointer to a procedure. It also allows you to use a function as a parameter. Its hard to explain this, so thats why i added a example script! Look and understand ;).
program New;
Type
Temp = Function(x:integer): string;
Cool = record
x : integer;
Func : Temp;
end;
var
A : Cool;
B : Temp;
Function Boo ( Funct : Temp;x : integer): string;
begin;
Result := Funct(x);
end;
Function Test (x : integer): string;
begin;
Result := IntToStr(x);
end;
begin
B := @Test;
Writeln(B(25));
A.Func := @Test;
A.x := 500;
Writeln(A.Func(A.x));
Writeln(Boo(@Test,5));
end.