Log in

View Full Version : Array Inv Color Boolean?



Le Jingle
05-11-2012, 08:11 AM
I'm having trouble (because I lack spunk/knowledge on Arrays) with coming up with a function where I check my Invent for an array of colors.

Ex. = Let's say I have a Inventory full of logs, like so:
http://i.imgur.com/siDzr.png

What I can think of so far, nowhere near perfect, nor claiming I thought of it all, nor does it even work, nor does it have the color looking for it too.. :/


Function CountInvArryColorsArea: Boolean;
Var
I: Byte;
Begin
Result:= False;
SetArrayLength(Result, 28);
For I:= 2 To 27 Do // I only need to look over invent spots 3-27
Result[I] := GetInven(i + 1);
End;


Again, my overall idea I'm trying to accomplish is this:
// CountInvArrayColorArea(color, InvSpotStart, InvSpotEnd): Boolean;
If (CountInvArryColorsArea(2, 27)) Then

so it we have the approypiate colors in each of our designated spots, they we can continue.. I'm half drunk, might be able to find somebody's script to see an example / similar ex, but help would be appreciated!

Flight
05-11-2012, 10:25 AM
I think I'm following you're saying here. You want to check inventory slot # 3-27 and make sure a specific color is found in each slot? Is that right?

Abu
05-11-2012, 03:00 PM
You could always grab a TBox around co-ordinates 5 to 28....

Runaway
05-11-2012, 05:22 PM
I haven't tested this or anything, but see if this works:


function CheckInvColor(Color, Tol, StartSlot, EndSlot: Integer): TBooleanArray;
var
i: Integer;
x, y: Integer;
Slot: TBox;
begin
if not LoggedIn then Exit;
SetArrayLength(Result, 28);
for i := StartSlot to EndSlot do
begin
Result[i] := False;
Slot := GetInven(i);
if ExistsItem(i) then
Result[i] := FindColorTolerance(x, y, Color, Slot.x1, Slot.y1, Slot.x2, Slot.y2, Tol);
end;
end;

Valithor
05-11-2012, 05:42 PM
Hey Le Jingle! I hope this helps! I've also tested the function in Runescape, and it works.
I haven't been able to figure out how to search an Array of Colors...
but if I can find out how to... I'll update this post.

Cheers!

Edit: StartInvBox and EndInvBox work on a scale from 0 to 27;
function SearchInvColor(Color, Tol: Integer; Hue, Sat: Extended; StartInvBox, EndInvBox: Integer): Boolean;
var
I, x, y, tmpCTS: integer;
invPattern: TIntegerArray;
slotBox:TBox;

begin
tmpCTS:= GetColorToleranceSpeed;
ColorToleranceSpeed(2); //searches using CTS 2
SetColorSpeed2Modifiers(Hue, Sat); //Hue and Sat modifiers

invPattern := [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28]; //the pattern it searches in

Writeln('Checking for colors in your Inventory.');
for I:= (StartInvBox) to (EndInvBox) do
begin
slotBox:= InvBox(invPattern[I]);
//Writeln('Checking item colors in InvBox['+IntToStr(invPattern[I])+']');
if (not FindColorTolerance(x, y, Color, slotBox.x1, slotBox.y1, slotBox.x2, slotBox.y2, Tol)) then
begin
Writeln('Could not find the color in InvBox['+IntToStr(invPattern[I])+']!');
Result:= false; // Could not find color
Exit; // Comment this line if you want
end;
end;

SetColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
Result:= true;
end;

Rich
05-11-2012, 05:43 PM
I haven't tested this or anything, but see if this works:


function CheckInvColor(Color, Tol, StartSlot, EndSlot: integer): boolean;
var
i: integer;
x, y: integer;
Slot: tbox;
begin
if not LoggedIn then Exit;
SetArrayLength(Result, 28);
for i := StartSlot to EndSlot do
begin
Result[i] := False;
Slot := GetInven(i);
if ExistsItem(i) then
Result := FindColorTolerance(x, y, Color, Slot.x1, Slot.y1, Slot.x2, Slot.y2, Tol);
end;
end;
Perhaps make the result an array of booleans, so we can see which slots don't have that colour?
function CheckInvColor(Color, Tol, StartSlot, EndSlot: integer): TBooleanArray;
var
i: integer;
x, y: integer;
Slot: tbox;
begin
if not LoggedIn then Exit;
SetArrayLength(Result, 28);
for i := StartSlot to EndSlot do
begin
Result[i] := False;
Slot := GetInven(i);
if ExistsItem(i) then
if FindColorTolerance(x, y, Color, Slot.x1, Slot.y1, Slot.x2, Slot.y2, Tol) then
Result[I]:= True;
end;
end;

Runaway
05-11-2012, 05:47 PM
Perhaps make the result an array of booleans, so we can see which slots don't have that colour?

Whoops, meant to do that :P

Rich
05-11-2012, 05:48 PM
Whoops, meant to do that :PYou still haven't changed the function type to TBooleanArray :p

Runaway
05-11-2012, 05:50 PM
You still haven't changed the function type to TBooleanArray :p

oy, there we go >.<

Le Jingle
05-13-2012, 06:31 AM
Type mismatch @ Slot:= GetInven(i);

I'll try to fix it myself, and nonetheless, thanks x1000 for the help. I'm thinking I should go to the library this week and try to find a couple of pascal books to check out to reference. :>

Edit : going to try this out


Function CheckInvColor(Color, Tol, StartSlot, EndSlot: Integer): TBooleanArray;
Var
i: Integer;
x, y: Integer;
Slot: TInvenItem;
Slota: Tbox;
Begin
If Not LoggedIn Then
Exit;
SetArrayLength(Result, 28);
For i:= StartSlot To EndSlot Do
Begin
Result[i]:= False;
Slot:= GetInven(i);
If ExistsItem(i) Then
Result[i]:= FindColorTolerance(x, y, Color, Slota.x1, Slota.y1, Slota.x2, Slota.y2, Tol);
End;
End;

Runaway
05-13-2012, 11:39 AM
Type mismatch @ Slot:= GetInven(i);

I'll try to fix it myself, and nonetheless, thanks x1000 for the help. I'm thinking I should go to the library this week and try to find a couple of pascal books to check out to reference. :>

Edit : going to try this out


Function CheckInvColor(Color, Tol, StartSlot, EndSlot: Integer): TBooleanArray;
Var
i: Integer;
x, y: Integer;
Slot: TInvenItem;
Slota: Tbox;
Begin
If Not LoggedIn Then
Exit;
SetArrayLength(Result, 28);
For i:= StartSlot To EndSlot Do
Begin
Result[i]:= False;
Slot:= GetInven(i);
If ExistsItem(i) Then
Result[i]:= FindColorTolerance(x, y, Color, Slota.x1, Slota.y1, Slota.x2, Slota.y2, Tol);
End;
End;


It might be easier to just use InvBox() as that will skip the need to convert a TInvenItem -> TBox. I don't know why I suggested GetInven() in the first place >.<


Function CheckInvColor(Color, Tol, StartSlot, EndSlot: Integer): TBooleanArray;
Var
i: Integer;
x, y: Integer;
Slot: Tbox;
Begin
If Not LoggedIn Then
Exit;
SetArrayLength(Result, 28);
For i:= StartSlot To EndSlot Do
Begin
Result[i]:= False;
Slot:= InvBox(i);
If ExistsItem(i) Then
Result[i]:= FindColorTolerance(x, y, Color, Slot.x1, Slot.y1, Slot.x2, Slot.y2, Tol);
End;
End;


That one should work fine, and it'll be a tiiiiny bit faster :)