SRL Archive - Help and Support

All sorts of shenanigans


kitchenrange

2010-12-23 00:38:33

In making a script for something completely unrelated some questions have come up. After a quick check of the includes I'm not sure how to go about this.

Ok so I have an array of long integers well say

01.01
02.03
02.04
02.02
10.03

Is there any way to compare all those integers to see if the digits after the decimal are the same.

I think I have found a way by creating my own type. It feels very similar to object oriented programming in c++. The only question I have about that is if I can create an array of the type I create using record. To clarify a little further, those integers describe characteristics about the places they hold. 01.01 for instance represents an Ace of Spades. 02.01 would be a Deuce of Spades, and changing the second set would change its suit 01.02 being an Ace of Hearts.
Using record I have created a type TCard and given it "fields" Suit and Rank. If I can create an array of those types,
it would represent a Hand and shit could get wild.

Type TCard = record
Rank : integer;
Suit : integer;
end;



Also, how would I go about reading text that has nothing to do with runescape? I mainly need this for text that I will supply a .bmp of in this thread. But it would also be good to read chat box text.


It seems I'm about to have to fire up the old mIRC.

Janilabo

2010-12-23 01:57:26

Do you mean like this..

type
TCardArray = array of record
Rank: Integer;
Suit: Integer;
end;

var
cardArray: TCardArray;

or you could do this too..

type
TCard = record
Rank: Integer;
Suit: Integer;
end;

var
cardArray: array of TCard;

-Jani

kitchenrange

2010-12-23 03:30:32

Your awesome. Do I declare the type above my global variable declarations or can I not have it as a global variable?

Of course I wouldn't have asked without playing around with it first.

lordsaturn

2010-12-23 03:48:45

procedure wut(ints: TIntegerArray): TIntegerArray;
var
i, Hi: Integer;
begin
Result := True;
Hi := High(ints);
for i := 0 to Hi-1 do
if ((ints[i] - floor(ints[i])) <> (ints[i+1] - floor(ints[i+1]))) then
begin
Result := False;
Break;
end;
end;

kitchenrange

2010-12-23 04:25:48

From: lordsaturn
procedure wut(ints: TIntegerArray): TIntegerArray;
var
i, Hi: Integer;
begin
Result := True;
Hi := High(ints);
for i := 0 to Hi-1 do
if ((ints[i] - floor(ints[i])) <> (ints[i+1] - floor(ints[i+1]))) then
begin
Result := False;
Break;
end;
end;


Im sorry Ill need some explanation for that. As far as I know you meant to write it as a function that returns a TIntegerArray? I'm not sure what it does
or how to apply it to what im doing. I definitely dont understand

if ((ints[i] - floor(ints[i])) <> (ints[i+1] - floor(ints[i+1]))) then

Thanks for the help.

Janilabo

2010-12-23 14:27:48

Hello again, kitchenrange. :)

I made a little example code for you, hoping it helps.

Here you go:

type
TCard = record
Rank, Suit: Integer;
end;
TCardArray = array of TCard;

function CreateCard(rank, suit: Integer): TCard;
begin
Result.Rank:= rank;
Result.Suit:= suit;
end;

function CreateCards(rankArr, suitArr: TIntegerArray): TCardArray;
var
hR, hS, i: Integer;
begin
hR:= High(rankArr);
hS:= High(suitArr);
if(hR <> hS)then
Exit;
if(hR > -1)then
begin
SetArrayLength(Result, (hR + 1));
for i:= 0 to hR do
Result[i]:= CreateCard(rankArr[i], suitArr[i]);
end;
end;

procedure PrintCards(cardArr: TCardArray);
var
h, i: Integer;
r, s: string;
begin
h:= High(cardArr);
if(h > -1)then
for i:= 0 to h do
begin
if(cardArr[i].Rank < 10)then
r:= ('0' + IntToStr(cardArr[i].Rank))
else
r:= IntToStr(cardArr[i].Rank);
if(cardArr[i].Suit < 10)then
s:= ('0' + IntToStr(cardArr[i].Suit))
else
s:= IntToStr(cardArr[i].Suit);
WriteLn('cardArr[' + IntToStr(i) + '] = ' + r + '.' + s);
r:= '';
s:= '';
end;
end;

var
cards: TCardArray;
suits, ranks: TIntegerArray;

begin
ranks:= [1, 2, 2, 2, 10];
suits:= [1, 3, 4, 2, 3];
cards:= CreateCards(ranks, suits);
SetArrayLength(ranks, 0);
SetArrayLength(suits, 0);
ClearDebug;
PrintCards(cards);
SetArrayLength(cards, 0);
end.

But there is waaaaay more than you can do, that's just a quick and small example. ;)

So, I recommend you to head at Tutorial Island. There's plenty of really good tutorials for types (and other scripting things) there. :)

Here, some type tutorials I picked to you from there:

..from beginner section…
Ultimate Type Tutorial by Daniel

..from intermediate section…
Types, Arrays, and Classes by Dan Cardin
Types and Arrays by nielsie95
Types! by SKy Scripter
Types + PlayerArray Tutorial by WhiteShadow

..from advanced section…
Records, Types, and Psuedo-OOP by Tniffoc

I also recommend to look for array tutorials from Tutorial Island (some, if not most, of those do explain about using arrays with types, though)

-Jani

kitchenrange

2010-12-23 14:38:17

Thanks alot for stopping by to clarify things for me. I just figured out the answer to my previous question right before checking back in though. I didn't realize I could declare the type and then also declare more global variables after. Ill definitely look into those tutorials. I noticed you disabled reputation. Any reason?

E: Also, the main question comes down to how to read text that has nothing to do with runescape. I'll be checking tutorials until I see an answer here or whichever comes first.

lordsaturn

2010-12-23 17:25:23

From: kitchenrange
Im sorry Ill need some explanation for that. As far as I know you meant to write it as a function that returns a TIntegerArray? I'm not sure what it does
or how to apply it to what im doing. I definitely dont understand

if ((ints[i] - floor(ints[i])) <> (ints[i+1] - floor(ints[i+1]))) then

Thanks for the help.


Yeah I changed it to return a boolean as I coded. ints is 9.07, floor(ints) is 9. 9.07 - 9 = .07. does the same for the next index, then compares them.

kitchenrange

2010-12-23 23:55:35

Ok forgive me if I seem dumb. Floor() separates the 9 from the .07?(Can you store decimal values in integers or maybe I misunderstood something?) And then you just subtract the floored number from the unfloored version to get the .07? Thank you again for your help.

I've solved the situation by creating TCard types and creating arrays of those. This has made the procedure for searching for cards much cleaner and smoother. Also is going to help when I rank my hands. :).


I'm hoping I can switch the focus and bring new attention to this thread without starting another, but my main problem now is recognizing text from any client. Thanks for any and all help.

Daniel

2010-12-24 02:47:39

function Int(X): Extended; will retrieve the non-decimal numbers. In (Object)Pascal, there is a reverse function named Frac (but IIRC that isn't included within Simba nor SCAR).

It's pretty easy to replicate though:

function Frac(X: Extended): Extended;
begin
Result := X - Int(X);
end;

//Int(6.0991); will return 6.
//Frac(6.0991); will return 0.0991.

So, you can use that to compare those decimal places :)


From: kitchenrange
Ok forgive me if I seem dumb. Floor() separates the 9 from the .07?(Can you store decimal values in integers or maybe I misunderstood something?)

Yes. Although technically, it rounds down.

From: kitchenrange
I'm hoping I can switch the focus and bring new attention to this thread without starting another, but my main problem now is recognizing text from any client. Thanks for any and all help.

You can look into the OCR methods that Simba offers (I've lost pretty much all my knowledge on this as it's been a while). :)