Hello and welcome to the Tutorial:
Types and Arrays
Chapters
- What's a type?
- How do I make a type?
- How do I set a type?
- How do I use a type?
- What's an array?
- How do I make an array?
- How do I use an array?
- Combining types and arrays
What is a type?
A type is a list of custom variables. The name of the type is called record. For example DoorProfiles:
SCAR Code:
type DoorProfile = record // This is the name of your type
Points: array of tpoint; // These are the things you can call out of a DoorProfile type. (Custom variables).
MidPoint: Tpoint;
PixelCount: integer;
Slope: extended;
Color:integer;
end;
Another example, the player array:
SCAR Code:
type
TUser = record
Name: string; // * User Name
Pass: string; // * User Pass
Nick: string; // * Screen Name for random detection
Active: Boolean; // * Set to True if Ok, False if Lost.
Loc: string; // * User Location
Rand: string;
Skill: string; // * User Action to Perform
Level: array[0..21] of word;
// * Levels of all skills. SetIn GetPlayerLevels.
Ore: string; // * test
WaitTime: Integer; // * Wait Time for Each User, Good for Autofighters
Fight: Boolean; // * If we want the Char to randomly fight
Worked: Integer; // * Time User has worked
Banked: Integer; // * Number of Banks User has done
Killed: Integer; // * Number of Kills User has made
Pin: Integer; // * Current Users Pin Number
Boolean1: Boolean; // * For reports, etc.
Boolean2: Boolean; // * For reports, etc.
Boolean3: Boolean; // * For reports, etc.
Integer1: Integer; // * For reports, etc.
Integer2: Integer; // * For reports, etc.
Integer3: Integer; // * For reports, etc.
Integer4: Integer; // * For reports, etc.
String1: string; // * For reports, etc.
String2: string; // * For reports, etc.
String3: string; // * For reports, etc.
Extended1: Extended; // * For reports, etc.
Extended2: Extended; // * For reports, etc.
Extended3: Extended; // * For reports, etc.
end;
Another example, TPoint:
SCAR Code:
type Tpoint = record
x, y: integer;
end;
How do I make a type?
If you start making a type, you need to have a name. The name is what you put between type and = record:
After the name you can just make a list of what you would like to integrate in you type:
SCAR Code:
type RGB = record
green: integer;
blue: integer;
red: integer;
{SHORTER:}
type RGB = record
green, blue, red: integer;
And what you don't need to forget: an end at the end of your list!!:
SCAR Code:
type RGB = record
green: integer;
blue: integer;
red: integer;
end;
{SHORTER:}
type RGB = record
green, blue, red: integer;
end;
How do I set a type?
You can only set types at the begin of you script. That means you can't set a type in a procedure or function!
If you set a type at the start of your script, it doesn't mean that it's a variable! If you take a look at the example of the player array above, you can see that the type is called TUser and not Players. That's why you need to set your type as a variable. Example:
SCAR Code:
var Player: TUser; //Now you can use the TUser in your script.
var RGBColors: RGB //Now you can use RGB in your script.
WRONG:
SCAR Code:
TUser.Name := ' '
TUser.Pass := ' '
TUser.Active := True;
RGB.Blue :=
RGB.Green :=
RGB.Red
GOOD:
SCAR Code:
var Player: TUser;
var RGBColors: RGB;
Player.Name := ' '
Player.Pass := ' '
Player.Active := True;
RGBColors.Blue :=
RGBColors.Greem :=
RGBColors.Red :=
How do I use a type?
You use your types just as you use a normal variable. Example:
SCAR Code:
a := 8;
b := 5;
RGBColors.Blue := 23;
RGBColorS.Green := 3;
RGBColors.Red := 80;
a := GetColor(123, 456);
RGBColors.Blue := GetColor(456, 789);
FindColor(Tpoint.x, Tpoint.y, 123, 456, 789, 765);
What is an array?
An array is a list of variables defined by numbers. Example:
SCAR Code:
var HeadColor: array[0..2] of Integer;
{ This will contain HeadColor[0], HeadColor[1], HeadColor[2] }
var MonsterColors: array of Integer;
{ This doesn't have a length yet }
How do I make an array?
To make an array, you first need to set your array as an variable:
SCAR Code:
var MonsterColors: array of integer; //If you don't know the length of the array yet
var MosterColors: Array[0..10] of integer; //If you know that the length will be 11 (you can also set something on 0).
Now you can define everything in the array:
SCAR Code:
{If you know the length:}
var MonsterColors: array[0..4] of integer;
MonsterColors[0] := 1;
MonsterColors[1] := 2;
MonsterColors[2] := 3;
MonsterColors[3] := 4;
MonsterColors[4] := 5;
{If you DONT know the length:}
var MonsterColors: array of integer;
MonsterColors := rs_ScanMiniMap(1234) //rs_ScanMiniMap will return all similar colors into an array of integer. It sets the length automaticly.
How do I use an array?
Now you have set your array, you can start using it:
SCAR Code:
If FindMSColor(x, y, MosterColors[0]) or FindMSColor(x, y, MosterColors[1]) or FindMSColor(x, y, MosterColors[2]) then WriteLn('One of the colors was found.);
The way above is the long way and most of the only only works if you know the length of the array. A quicker and way more used way to do it is this:
SCAR Code:
var i: integer;
{If you know the length:}
for i := 0 to 4 do //This will perform FindMSColor 5 times with every time an other part of the array
begin
if FindMSColor(x, y, MonsterColors[i]) then WriteLn('Color found');
end;
{If you DONT know the length - This way can also be used for the array above}
//With GetArrayLength you get the length of the array. You always have to do -1 after GetArrayLength if you use for..do!!!
for i := 0 to GetArrayLength(MonsterColors) -1 do
begin
if FindMSColor(x, y, MonsterColors[i]) then WriteLn('Color found');
end;
Combinding types and arrays
It may be very handy to combine types and arrays. For example the PlayerArray is built this way. First there was made a type of one user (Tuser) and after that they made an array of TUser (Named Players):
This way you can easily set all your players:
SCAR Code:
Players[0].Name :='';
Players[0].Pass :='';
Players[0].Nick :='';
Players[0].String1 :='';
Players[0].Integer1 := 1 ;
Players[0].Active := True;
Players[0].Boolean1 := True;
Players[1].Name :='';
Players[1].Pass :='';
Players[1].Nick :='';
Players[1].String1 :='';
Players[1].Integer1 := 1 ;
Players[1].Active := True;
Players[1].Boolean1 := True;
There are various other this where it may be handy to combine types with arrays. But I hope that after reading this tutorial you have the knowledge you make them yourself!
Thanks for reading,
Nielsie95