# Thread: A list of common Types in SCAR - Plus making your own!!

1. ## A list of common Types in SCAR - Plus making your own!!

A list of common Types in SCAR - Plus making your own!!

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.

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
SCAR Code:
`end;`
is where your Variables will go into.

SCAR Code:
`Type Rock = recordend;`

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

^ Which tought me some pretty cool stuff ^
Last edited by Naum; 07-01-2009 at 03:05 AM.

2. I for some reason really like this tutorial.
I hope that more people will read it.

I don't really know why I like it, but I also enjoy the fact that you continue writing tutorials even after receiving the cup.

Keep it up -- and I mean it

Rep+ for you.

3. Senior SRL Member
Join Date
Jan 2008
Location
NC, USA.
Posts
4,435
Mentioned
0 Post(s)
Quoted
2 Post(s)
that was great! repped and using in my script!

4. Thats really is a great walk through TUT.
Very Informative.
Great Job Nauman!

5. Banned
Join Date
Oct 2007
Location
If (Online) then Loc := ('On comp') else Loc := ('Somewhere else!');
Posts
2,022
Mentioned
0 Post(s)
Quoted
0 Post(s)
wow man jsust wow your are just getting better and better at all this

you nver sese to amaze

6. On a small note, it is generally nice that when you make a type to add 'T' in front of it.
(TPoint, TBox, etc.) This, so you can actually use the variable 'Lunch' in your example.
SCAR Code:
`Var   Lunch: TLunch;`
Might be worth explaining as well.
Good tutorial.

7. Bump! Great tut... using record in my script, and this helped me understand them more!

8. Banned
Join Date
Jan 2008
Location
California, US
Posts
2,790
Mentioned
0 Post(s)
Quoted
0 Post(s)
Also note that you can use types of custom types you make and not just string, bool, float, etc.

SCAR Code:
`program new;type  a = record    s : string;  b = record    d : a;  end;beginend.`

9. Banned
Join Date
Jan 2008
Location
California, US
Posts
2,790
Mentioned
0 Post(s)
Quoted
0 Post(s)
haha, nope put in by accident ;p.

10. "Set of" types are quite useful if you want to call a certain type of food for example. EG:

SCAR Code:
`Type  FoodType = set of (Lobster, Shark, Something else);  Player = record    Name, Pass, Nick: String;    YourFood: FoodType.  end;Var  Players: Array of Players;`

Not sure if this is in SCAR, but its in Pascal.

11. I don't think you do that in SCAR, I think its this.
SCAR Code:
`Type  FoodType = (Lobster, Shark, Somethingelse);  Player = record    Name, Pass, Nick: String;    YourFood: FoodType.  end;Var  Players: Array of Players;`

At least that is how Text.scar does it...

12. Registered User
Join Date
Jun 2009
Posts
8
Mentioned
0 Post(s)
Quoted
0 Post(s)
Var Vrnt : TVariantArray;

Begin
Vrnt := ['gh', 124, 78.65, #50+#65, 9999999999999999999999999]
Wow, lol, I totally forgot you could do that with array's.
It's been a while, thanks for the reminder!
BTW: 'I' isn't defined in that same section, although I can see why you might not have put it in. =p

13. Banned
Join Date
Dec 2008
Posts
2,829
Mentioned
0 Post(s)
Quoted
0 Post(s)
Originally Posted by scyk123
Wow, lol, I totally forgot you could do that with array's.
It's been a while, thanks for the reminder!
BTW: 'I' isn't defined in that same section, although I can see why you might not have put it in. =p
He forgot to put it in. Thanks (on Naum's behalf ).

(By the way, I'm excited to see what you can do with SCAR since you already know arrays )

14. Originally Posted by Richard
"Set of" types are quite useful if you want to call a certain type of food for example. EG:

SCAR Code:
`Type  FoodType = set of (Lobster, Shark, Something else);  Player = record    Name, Pass, Nick: String;    YourFood: FoodType.  end;Var  Players: Array of Players;`

Not sure if this is in SCAR, but its in Pascal.

15. Bumping for generally being a good tut. Also was looking to see if I could se this in my script but alas I don't think it's what I need. This is easier to understand and more in depth than most of the other tuts.

I have 2 integer's and 3 array of string but I need it to choose one of each based on some conditions that are preset in the player array.