Contents
I - Intro.
II - Known Types In SCAR. (And stuff you didn't know)
III - Not that-well-known types in SCAR.
IV - Make your own types.
V - End Note.
I - Intro
Hello all, welcome to my..11th.. tutorial so far. In this tutorial I will try and drum-up the 'most' comprehensive List Of Types in SCAR. And hopefully explain how you can make your own.
So lets begin. What is a Type
Types are data storing variables. The most commonly known are:
SCAR Code:
Integer; String; Extended; Boolean; Char; Byte; Variant; TPoint;
You should know at least 4 of them to continue. If you don't know many of them, don't despair as I will explain them later on .
II - Known Types In SCAR
Most common types in SCAR:
The Integer
X : Integer; <-- An integer is a data type which stores any whole number from -2,147,483,648 to 2,147,483,647 inside it. Basically it stores any whole number in between those ranges. Which in this case is X. If you try any more than those parameters you will get 0.
e.g
SCAR Code:
Var X : Integer;
Begin
X := 2147483649;
WriteLn(IntToStr(X));
end.
The String
Str : String; <-- A string is a data type which stores any part of text inside it. It stores strings of Chars(alphabet) and Numbers. It holds up to any size desired. You don't have to convert it, to make it work in WriteLn, as it is it's origonal type (WrteLn).
e.g
SCAR Code:
Var Str : String;
Begin
Str := 'hash9785409lol###./\,powq';
WriteLn(Str);
end.
The Extended
Ext : Extended; <-- An Extended is a data type which stores decimal or floating numbers. It stores up to 19 significant figures. In Scar it has a bigger exponant that it has in delphi.
e.g
SCAR Code:
Var
Ext : Extended;
begin
Ext := 50056.6767676776;
WriteLn(FloatToStr(Ext));
end.
The Boolean
Bool : Boolean; <-- A Boolean is a data type which stores a True or False statement inside it. Nothing so special about this one, this is a logical data type used very often in functions and such. You could make your own like this :
e.g
SCAR Code:
type
Bool = (True, False);
var
suit : Bool;
The Char
Chr : Char; <-- A Char is a data type which stores a single character in the '#(Number here)' form. For instance #39 is ' . The String uses an array of Char's.
e.g
SCAR Code:
Var Chr : Char;
begin
Chr := #39;
WriteLn(Chr);
end.
The Byte
Byt : Byte; <-- A Byte is a data type which stores a whole number from 0 - 255. Mostly used for saving space. It's part of the integer value. If you go further then the range then it will return '0'
e.g
SCAR Code:
Var I : Byte;
Begin
I := 256;
WriteLn(IntToStr(I));
The Variant and TVarriantArray
Vrnt : Variant; <-- A Variant is an undefined variable, you can treat it as any type of variable you want to. You can set it as Strings, Extendeds, Integer; so on.
I would think that the Variant is the most useful type when dealing with unknown types. Simply put it takes any type you put into it.
e.g
SCAR Code:
Var x, y, Vrnt : Variant;
Begin
X := 2;
Y := 'lol'
Vrnt := 46.75;
WriteLn(Vrnt);
WriteLn(Y);
WriteLn(X);
end.
You see - there is no need to convert it .
A TVariantArray is an Array of Variant. It takes any length and any data type .
e.g
SCAR Code:
Var Vrnt, I : TVariantArray;
Begin
Vrnt := ['gh', 124, 78.65, #50+#65, 9999999999999999999999999]
For I := 0 to High(Vrnt) Do
WriteLn(Vrnt[I]);
end.
Please not you cannot WriteLn any of the data types in the Variant Array. For instance 'gh', 124 so on, Unless you set Vrnt to nil(null).
The TPoint and TPointArray
TP : TPoint; <-- A TPoint is a Record type, which holds X and Y Integer values. This is normally used to hold a 2 dimensional co-ord. Like when it's used in an Array for for TPA finding.
A TPointArray usually abbreveated to TPA, Is an Array of TPoint. And is used in object finding.
For More info : http://www.villavu.com/forum/showthread.php?t=38295
III - Not that-well-known types in SCAR.
God finally... All that reading, now we get to the 'cool' stuff -_-.. But believe me half of these you wouldn't know were in SCAR. If you do delphi you may know about alot of them.
Values found from some site .
String Types
Str2 : WideChar; // Holds a single character, International alphabet - a,b,c - ?,?,?.
Str7 : WideString; // Holds strings of WideChar's of any size.
Conversion Variant or None
Integer Types
Int1 : Byte; // 0 to 255
Int2 : ShortInt; // -127 to 127
Int3 : Word; // 0 to 65,535
Int4 : SmallInt; // -32,768 to 32,767
Int5 : LongWord; // 0 to 4,294,967,295
Int6 : Cardinal; // 0 to 4,294,967,295
Int7 : LongInt; // -2,147,483,648 to 2,147,483,647
Int8 : Integer; // -2,147,483,648 to 2,147,483,647
Int9 : Int64; // -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
Conversion - Variant or IntTo.., Int64to.. .
Extended Types - Decimal Types.
Dec1 : Single; // 7 significant digits.
Dec2 : Currency; // 50+ significant digits, fixed 4 decimal places
Dec3 : Double; // 15 significant digits.
Dec4 : Extended; // 19 significant digits.
Conversion - Variant or FloatTo..
There is also a nifty function in SCAR called [b]VarType();[/scar]. This will return what type of variant that is defined as.
For instance the VarType For some variables are as follows:
Common:
256 --> String, Char;
3 --> Integer, LongInt;
5 --> Extended;
11 --> Boolean;
8204 --> Arrays such as TPA and TStringArray;
0 --> Variant;
17 --> Byte;
Not that common:
5 --> Double;
16 --> ShortInt;
18 --> Word;
2 --> SmallInt;
19 --> LongWord, Cardinal;
20 --> Int64;
5 --> Single (same as Extended).
6 --> Currency;
IV - Make your own types.
Okay now the fun starts..
I'm only going to be talking about Records and simple Types
You may wonder what is the use of Types, they're just another confusing thing. Guess what?? There easy!!
RECORDS!!!
Definition Of Records : Record data structure can mix any of SCAR's built in types.
4 Steps to making your Record
1. Declare your type, for instance mine will be Rock. Put a record on the end of it, and also put an [b]end;[/scar] at the end of it. In between the Type and is where your Variables will go into.
2.Now add whatever vairables you want into it, I will add some rock characteristics.
SCAR Code:
Type Rock = record
UpText : String;
Color : Integer;
Tolerance : Byte;
ClickLeft : Boolean;
end;
3.Then all you need to do is add a var section underneith it and declare a Variable as your type. Confusing study this code:
SCAR Code:
Type Rock = record
UpText : String;
Color : Integer;
Tolerance : Byte;
ClickLeft : Boolean;
end;
Var Iron : Rock
4. Now use it in your script. E.g
SCAR Code:
Type Rock = record
UpText : String;
Color : Integer;
Tolerance : Byte;
ClickLeft : Boolean;
end;
Var Iron : Rock;
x, y : Integer;
Begin
Iron.UpText := 'ron'; //Rock uptext
Iron.Color := 35443; //Color of Iron Rock
Iron.Tolerance := 10; //Tolerance of Rock
Iron.ClickLeft := True; //Clicks left on Rock
If FindObj(x, y, Iron.UpText, Iron.Color, Iron.Tolerance) Then
Mouse(x, y, 5, 5, Iron.ClickLeft);
end.
And you dont really have to do '.' something for records, you can also use a With and Do statement.
Like :
SCAR Code:
Type Rock = record
UpText : String;
Color : Integer;
Tolerance : Byte;
ClickLeft : Boolean;
end;
Var Iron : Rock;
x, y : Integer;
Begin
With Iron Do
Begin
UpText := 'ron'; //Rock uptext
Color := 35443; //Color of Iron Rock
Tolerance := 10; //Tolerance of Rock
ClickLeft := True; //Clicks left on Rock
end;
If FindObj(x, y, Iron.UpText, Iron.Color, Iron.Tolerance) Then
Mouse(x, y, 5, 5, Iron.ClickLeft);
end.
This method is also used in Rons form parser and in FindObjRecord . Records help save time and money??
Please Note : It is generally nice that when you make a type to add 'T' in front of it.(TPoint, TBox, etc.) . So It should be TRock instead of just Rock
SIMPLE TYPES + SETS!!!
A type is used to set the input used by a procedure:
Such as:
SCAR Code:
Type
Lunch = (Chips, Pasta, Salad);
And you can use it by using a set. The Set keyword dspecifies a type for up to 255 whole values. A set variable always holds all values put inside, you can choose which ones to add. So for instance.
SCAR Code:
Type
Lunch = (Chips, Pasta, Salad);
Var Lunchh : set of Lunch;
procedure WhatToHave_For_Lunch;
Begin
If Chips in Lunchh Then
WriteLn('Were having chips')
Else
WriteLn('No chips :(');
end;
Begin
Lunchh := [Chips, Salad];
WhatToHave_For_Lunch;
end.
This procedure checks what is in the set 'Lunchh' you can remove chips from that set to make the output change .
In is a very useful command as it checks if that value is in the set.
There are alot of uses for sets one of the most common common example I can think of is in Tic Tac Toe by SKy_Scripter and Tins by Markus (check the games folder in scar for these)
V - End Note.
Credits
Two of the best tutorials : http://www.villavu.com/forum/showthread.php?t=18778
http://www.villavu.com/forum/showthread.php?t=9746
^ Which tought me some pretty cool stuff ^