SRL Archive - OSR Help

Strange count colour error


Bonfield

2010-12-20 05:21:47

can someone tell me why


program new;
{$i SRL/SRL.scar}
{$i SRL/SRL/Misc/Stats.scar}
{$i SRL/SRL/Misc/Users.scar}
{$i SRL/SRL/Misc/Reports.scar}
{$i SRL/SRL/Misc/Debug.scar}

function Get_Black_Count(Slot, Color: Integer; Bank: Boolean): Integer;
var
b: TBox;
begin
Result := 0;
if Bank then
b := BankIndexToMSBox(Slot)
else
b := InvBox(Slot);
Result := CountColor(Color, b.X1, b.Y1 + 15, b.X2, b.Y2);
end;

function Count_Items(Count, Start_Slot, Finish_Slot: Integer; out Slots: array of Integer): Integer;
var
i: Integer;
begin
SetLength(Slots, 50);
Result := 0;

for i := Start_Slot to Finish_Slot do
if(Get_Black_Count(i, SRL_OUTLINE_BLACK, true) = Count) then
begin
Inc(Result);
Slots[Result - 1] := i;
end;

SetLength(Slots, Result);
end;

procedure OutputArray(const Arr: TIntegerArray; Write: string);
var
I, ArrLength: Integer;
S: string;
begin
ArrLength := High(Arr);
S := ' ' + Write + ' := [';

for I := 0 to ArrLength do
S := S + IntToStr(Arr[I]) + ', ';

Delete(S, Length(S) - 1, Length(S));
S := S + '];';
Writeln(S);
end;

var
i, Item_Amount, ColourCount :integer;
SlotsIn: array of Integer;

begin
setupSRL;
ActivateClient;
wait(1000);
ColourCount := Get_Black_Count(1, srl_outline_black, False); // tried with SRL's constant. and 131072 all are 35
writeln('Colour Count is '+inttostr(ColourCount));
for i := 1 to 12 do
begin
writeln(inttostr(Get_Black_Count(i, srl_outline_black, false)));
end;
Item_Amount := Count_Items(35,1,12,SLOTSIN);
OutputArray(SlotsIn, 'COUNT ITEMS:')
writeln('Item Amount is '+inttostr(Item_Amount));
end.

outputs

Compiled succesfully in 1825 ms.
SRL Compiled in 16 msec
Colour Count is 35
35
39
35
39
35
35
35
39
35
35
35
39
COUNT ITEMS: :=];
Item Amount is 0
Successfully executed.

when the inventory is

when item amount should equal 8 and slots in should be 1, 3, 5, 6, 7, 9, 10, 11

i really have no idea why, its already in safe mode and i have tried with SMART

Boreas

2010-12-20 09:26:24

if(Get_Black_Count(i, SRL_OUTLINE_BLACK, true) = Count) then
try false?

Gu3st...

2010-12-20 14:12:22

Also, Simba is capable of outputting whole arrays.. Just do WriteLn(Array); :)
Oh, and types too… WriteLn(TMufasaBitmap); would work and so on…

function Count_Items(Count, Start_Slot, Finish_Slot: Integer; Bank : Boolean; out Slots: array of Integer): Integer;
var
i: Integer;
begin
SetLength(Slots, 50);
Result := 0;

for i := Start_Slot to Finish_Slot do
if(Get_Black_Count(i, SRL_OUTLINE_BLACK, Bank) = Count) then
begin
Inc(Result);
Slots[Result - 1] := i;
end;

SetLength(Slots, Result);
end;
Would work :)

Bonfield

2010-12-20 14:31:51

From: Boreas
if(Get_Black_Count(i, SRL_OUTLINE_BLACK, true) = Count) then
try false?

I'm pretty sure thats all I need to change, I have noidea when I changed that function because at the moment it always make a TBox of the bank boxes instead of inventory like I thought it was doing, I can not check it right now I will have to wait till this arvo
From: Zyt3x
Also, Simba is capable of outputting whole arrays.. Just do WriteLn(Array); :)
Oh, and types too… WriteLn(TMufasaBitmap); would work and so on…

function Count_Items(Count, Start_Slot, Finish_Slot: Integer; Bank : Boolean; out Slots: array of Integer): Integer;
var
i: Integer;
begin
SetLength(Slots, 50);
Result := 0;

for i := Start_Slot to Finish_Slot do
if(Get_Black_Count(i, SRL_OUTLINE_BLACK, Bank) = Count) then
begin
Inc(Result);
Slots[Result - 1] := i;
end;

SetLength(Slots, Result);
end;
Would work :)


I'm positive that's how I originally wrote that function, thankyou

I didn't know about writeln(Array) or writeln(TMufasaBitmap) I will look at them later today

Thankyou for looking at this, I will post back here if that fixed it but I'm certian that's the error

Gu3st...

2010-12-20 14:49:37

I think WriteLn(TMufasaBitmap); Would either return a runtime error or print out "nil" though :P so it would be better to test with your own types ;)
Like this:
type
Stuff = record
Blah : Integer;
Foo, Bar : String;
end;

Bonfield

2010-12-21 01:50:31

adding the InBank boolean fixed it, i had wrked on my script for a while and i was certian there was nothing wrong with any of my functons, and it was such a simple frustrating error

thanks for telling me about that, how long has writeln(Array) be functonal in simba?

im sure i will ue writeln(TMufasaBitmap) somewhere it will be useful for debugging

Gu3st...

2010-12-21 05:58:13

Yes, this is very helpful for debugging :)
I'm not sure for how long it's been in Simba, but it's been for a while..
Glad you worked it out :)