PDA

View Full Version : Types!



SKy Scripter
10-09-2007, 01:44 AM
Types


In This tut you will learn types and gain a better knowledge of SCAR....

first off, i would like to start with This type , these types can be used for multi purpose



type
GamePos = (StartMenu, GamePlay, EndGame);

var
GP : GamePos;
begin
Gp := StartMenu;
if (Gp = StartMenu) then Writeln('Woot!, Yeah!');
end.


Like.... We can declare it... Startmenu
then we can check to see if it is equal to it.... in which case we can draw a
start menu... because we know where we are...


if (GP = StartMenu) then
begin
writlen('Drawwing Start Menu');
Drawmenu;
end;

Also, you can use this to switch somthing for example :

program Switcher;
type
Tswitch = (s1, s2, s3, sdone);

var k : Integer;
s : Tswitch;
begin
repeat
k := k + 1;
case k of
1 : s := s1;
2 : s := s2;
3 : s := s3;
else
s := sdone;
end;

case s of
s1 : Writeln('S = S1 ');
s2 : writeln('S = S2 ');
s3 : writeln('S = S3 ');
sdone : Writeln('s = Done!');
end;

Wait(1000);
until false;


end.


Ok, you might want to know if its possible to have a type that equal more then one thing at a time! well guess what there is! this would be a Set Type These are extremly helpful in some cases...





type
GamePos = (StartMenu, GamePlay, EndGame);
SetGamePos = set of GamePos;
var
GP : SetGamePos;
begin
Gp := [StartMenu];
Gp := Gp + [EndGame];
if (StartMenu in Gp) then Writeln('Woot!, Yeah!');
end.


notice how i put "gp := gp + [Endgame];" Well this is how you add on...
but remember this only works for types that are set

type
TSetboolean = set of boolean;

also The only types that can be set are types that are qual to certain values which would exclude strings, integers, and extended....

Another away to set a type is...


S := [sbmenu, sbmenu2];

if (sbmenu in s) then Writeln('Your currently at the menu...');


look at my example of a very good reason to why its helpful...
this is my CERTER Solver XD



type
TCerterInven =(tcRing, tcKite, tcHelmet,
tcShears, tcBowl, tcFish, tcSword, tcSpade, tcAxe);
TCerter = set of TCerterInven;


const
DebugCerter = True;

{************************************************* ******************************
function FindCerterScreen : Boolean;
by: SKy Scripter
Description: Returns true if find certer screen
************************************************** *****************************}
function FindCerterScreen : Boolean;
var
Color : Integer;
begin
Color := GetColor(151, 151);
Result := (LoggedIn) and
(CountColor(Color, 151, 151, 251, 251) > 9000)
end;

{************************************************* ******************************
function FindCerterPixels : TPointArray;
by: SKy Scripter
Description: Returns All Certer Object Pixels.
************************************************** *****************************}
function FindCerterPixels : TPointArray;
var
P : TPointArray;
ColorData : TIntegerArray;
i, a, BackGround : Integer;
begin
if (not(FindCerterScreen)) then Exit;
BackGround := GetColor(151, 151);
FindColorsTolerance(P, BackGround, 151, 151, 376, 294, 255 * 3);
ColorData := GetColors(P);
SetArrayLength(Result, 30800); // 30800 >> as many point possible
for i := 0 to Length(P)-1 do
if (ColorData[i] <> BackGround) then
begin
Result[a] := P[i];
inc(a);
end;
SetArrayLength(Result, a);
end;


{************************************************* ******************************
function FindCerterInfo(var Width, Height, Count : Integer) : Boolean;
by: SKy Scripter
Description: Returns The Width, Height and Pixel Count.
************************************************** *****************************}
function FindCerterInfo(var Width, Height, Count : Integer) : Boolean;
var
MaxP, MinP : TPoint;
P : TPointArray;
l, I, C : Integer;
label Restart;
begin
Restart :
C := C + 1;
wait(100);
if (FindCerterScreen) then
begin
P := FindCerterPixels;
l := Length(P);
if (l = 0) then begin Writeln('Could Not Find Any Certer Pixels'); Exit; end;
MaxP := P[0];
MinP := P[l-1];
for I := 1 to l-2 do
begin
if (MaxP.x < P[i].x) then MaxP.x := P[i].x;
if (MaxP.y < P[i].y) then MaxP.y := P[i].y;
if (MinP.x > P[i].x) then MinP.x := P[i].x;
if (MinP.y > P[i].y) then MinP.y := P[i].y;
end;
Width := MaxP.x - MinP.x;
Height := MaxP.y - MinP.y;
Count := l;
Result := True;
end else
if (C < 15) then goto Restart else Exit;
end;

{************************************************* ******************************
function findcerterquestions : TCerter;
by: SKy Scripter
Description: finds the certer questions.
************************************************** *****************************}
function findcerterquestions : TCerter;
var
s : array of string;
i, c, x, y : Integer;
begin
s := ['pair', 'bowl', 'fish', 'sword',
'spade', 'axe', 'helmet', 'shield',
'ring'];

for i := 0 to Length(s)-1 do
if (FindText(x, y, s[i], NPCChars, 69, 41, 184, 136)) then
begin
case S[i] of
'pair' : Result := Result + [tcShears];
'bowl' : Result := Result + [tcBowl];
'fish' : Result := Result + [tcFish];
'sword' : Result := Result + [tcSword];
'spade' : Result := Result + [tcSpade];
'axe' : Result := Result + [tcAxe];
'helmet': Result := Result + [tcHelmet];
'shield': Result := Result + [tcKite];
'ring' : Result := Result + [tcRing];
end;
inc(c);
Writeln(inttostr(c)+'. ' + S[i]);
end;
end;


{************************************************* ******************************
function SkyFindCerter : Boolean;
by: SKy Scripter
Description: Solves Certer random then returns true if solved.
************************************************** *****************************}

function SkySolveCerter : Boolean;
var Width, Height, Count, n, l, i, x, y : Integer;
S : string;
Certers : TCerter;
begin
if (not(FindCerterScreen)) then Exit;
Certers := findcerterquestions;
while (N <> 1) do
begin
n := 0;
if (FindCerterScreen) then
begin
inc(l);
if (FindCerterInfo(Width, Height, Count)) then
begin
if (Height > Width) or (i > 15)
or (Width - Height < 4) then
begin

if (tcBowl in Certers) then
if (Abs(Count - 3400) <= 300) and (Abs(Width - Height) <= 15)
and (Width + Height > 100) then
begin
s := 'bowl';
inc(n);
end;

if (tcFish in Certers) then
if (Abs(Count - 2500) <= 200) and (Abs(Width + Height - 160) <= 10) then
begin
s := 'fish';
inc(n);
end;

if (tcSword in Certers) then
if (Abs(Count - 500) <= 200) and (Abs(Width + Height - 100) <= 15) then
begin
s := 'sword';
inc(n);
end;

if (tcSpade in Certers) then
if (Abs(Count - 1400) <= 200) and (max(width, height) > 70)
and (Abs(Width + Height - 156) <= 16) then
begin
s := 'spade';
inc(n);
end;

if (tcAxe in Certers) then
if (Abs(Count - 1300) <= 200) and (Abs(Width + Height - 135) <= 20)
and (max(width, height) > 80) then
begin
s := 'axe';
inc(n);
end;

if (tcHelmet in Certers) then
if (Abs(Count - 1100) <= 100) and (Abs(Width + Height - 80) <= 15) then
begin
s := 'helmet';
inc(n);
end;

if (tcKite in Certers) then
if (Abs(Count - 3200) <= 300) and (Abs(Width - Height) <= 15) then
if (Max(width, Height) > 69) then
begin
s := 'shield';
inc(n);
end;

if (tcShears in Certers) then
if (Abs(Count - 600) <= 400) and (Abs(Width - Height) >= 5) then
begin
s := 'pair'; // Width = 44 Height = 46
inc(n); // Object Count = 836
end;

if (tcRing in Certers) then
if (Abs(Count - 800) <= 200) and (Abs(Width - Height) <= 10) then
begin
s := 'ring';
inc(n);
end;

end else Inc(i);
if (S<>'') then
begin
if (DebugCerter) then
begin
Writeln('Width = ' + inttostr(Width) + ' Height = ' + inttostr(height));
Writeln('Object Count = ' + inttostr(Count));
Writeln('Certer = '+ S);
end;
if FindText(x, y, s, NPCChars, 69, 41, 184, 136) then
begin
Mouse(93, y, 15, 15, True);
Writeln('Solved, Certer!');
Result := True;
Exit;
end;
end;
end;
if (l = 20) then Exit;
end else Exit;
end;
Wait(100 + Random(1000));
Result := True;
end;


Ok Next, Record Types, i would have to agree this is what might be the most helpful IN Scar :p.this allows you to hold more then one type in one type :D

Learn from my example below :


type
GamePos = (StartMenu, GamePlay, EndGame);
SetGamePos = set of GamePos;

TGame = record
Pos : GamePos;
SetPos : SetGamePos;
Run : record
why : string;
b : boolean;
end;
end;


var
GP : TGame;
begin
Gp.setpos := [StartMenu];
Gp.setpos := Gp.setpos + [EndGame];
gp.run.why := 'Just Because!!';
gp.run.b := (EndGame in Gp.setpos);
if (gp.run.b) then Writeln( gp.run.why);
end.


Ok For the next Type :) Arrays woot ! :p heres an example of Arrays..


type
GamePixels = array of record
x, y, color : Integer;
end;



Ok Just Learn from them, see easy. ;) Lol..

Cant think of any other at the moment..



Still Updating

IronTeapot
10-09-2007, 04:01 AM
After reading this, i have no clue what the point of Types are. Maybe explain their uses in an example, and for your record types, comment on what its actually doing and such.

SKy Scripter
10-09-2007, 04:24 AM
After reading this, i have no clue what the point of Types are. Maybe explain their uses in an example, and for your record types, comment on what its actually doing and such.

Lol, yeah i didnt spend much time on this tut sorry XD

edit : tomorrow i might just delete it all and type a real tut ;)

BobboHobbo
10-09-2007, 04:48 AM
Lol, yeah i didnt spend much time on this tut sorry XD

edit : tomorrow i might just delete it all and type a real tut ;)

Mmm tommorow :( why not now? :)

BTW in your sig, quiz random is that the thing like who wants to be a million air show thingy like you sit with the host and answer questions?

SKy Scripter
10-09-2007, 05:32 AM
Mmm tommorow :( why not now? :)

BTW in your sig, quiz random is that the thing like who wants to be a million air show thingy like you sit with the host and answer questions?


yeah... :p cant now going to bed XD, yes that the quiz

ZephyrsFury
10-09-2007, 01:20 PM
Meh. I don't really get that Set type one especially the Gp := Gp + [EndGame] bit. And is this right:


Run : record
why : string;
b : boolean;
end;


Should it be this:


Run = record //Notice equals sign.
why : string;
b : boolean;
end;


I'm not sure but it makes more sense.

Tim0suprem0
10-15-2007, 03:39 AM
This made me really confused, but looking at your certer kinda helped :p Anyways if you could clean it up and explain a little that'd be nice :)