SRL Archive - OSR Help

how can i shorten this procedure


fORCE_wORKS

2010-03-19 00:33:56

i want the procedure to do the same job. there must be a shorter way to do it. how would i swap the bitmaps to search for the next one.


procedure CountCargoBay;
begin
if(findbitmaptolerancein(MyCargo,cx,cy,1,25,1605,927,80))then
begin
if(findbitmaptolerancein(C0,x,y,1,25,1605,927,80))then
begin
CargoCount:= 0;
Exit;
end;
if(findbitmaptolerancein(C1,x,y,1,25,1605,927,80))then
begin
CargoCount:= 1;
Exit;
end;
if(findbitmaptolerancein(C2,x,y,1,25,1605,927,80))then
begin
CargoCount:= 2;
Exit;
end;
if(findbitmaptolerancein(C3,x,y,1,25,1605,927,80))then
CargoCount:= 3;
end else
begin
writeln('Could Not Count Cargo');
end;
end;

Wanted

2010-03-19 00:35:28

Make C: TIntegerArray and do a for do loop?

YoHoJo

2010-03-19 00:44:49

This code is definitely not 100% right, but hopefully you'll get the idea, and I see IceFire is looking at this thread, so HIS idea will definitely pwn my idea, so use his (if he posts :p)

var
MyBitMaps:array [1..5] of Integer;

Procedure LoadMyBitmaps:
Begin
MyBitMaps[1]:=BITMAP HERE;
MyBitMaps[2]:=BITMAP HERE;
MyBitMaps[3]:=BITMAP HERE;
MyBitMaps[4]:=BITMAP HERE;
MyBitMaps[5]:= BITMAP HERE;
End;

procedure CountCargoBay;
begin
For I:=1 To 5 Do
Begin
if(findbitmaptolerancein(MyBitMaps[I],cx,cy,1,25,1605,927,80))then
Begin
I:=I+1
if(findbitmaptolerancein(MyBitMaps[I],x,y,1,25,1605,927,80))then
begin
CargoCount:= 0;
Break;
end;
I:=I+1;
if(findbitmaptolerancein(MyBitMaps[I],x,y,1,25,1605,927,80))then
begin
CargoCount:= 1;
Break;
end;
I:=I+1;
if(findbitmaptolerancein(C2,x,y,1,25,1605,927,80))then
begin
CargoCount:= 2;
Break;
end;
I:=I+1;
if(findbitmaptolerancein(C3,x,y,1,25,1605,927,80))then
Begin
CargoCount:= 3;
Break;
End;
End Else
Writeln('Didnt Find MyCargo');
end;

Edit: Pretty much same idea, he'd probably code it better though :p

i luffs yeww

2010-03-19 00:46:44

YoHoJo, you increment I a few times. >_> You don't even use the loop, do you?

Sex

2010-03-19 00:54:02

procedure LoadBitmaps;
begin
Bmps[0] :=
Bmps[1] :=
Bmps[2] :=
Bmps[3] :=
end;

procedure CountCargoBay;
var
i, cx, cy : integer;
begin
if FindBitmapToleranceIn(MyCargo, cx, cy, 1, 25, 1605, 927, 80) then
begin
for i := 0 to 3 do
if FindBitmapTOleranceIn(Bmps[i], cx, cy, 1, 25, 1605, 927, 80) then
begin
CargoCount := i;
exit;
end;
end else
Writeln('Could Not Count Cargo');
end;
Along the lines of that :).

fORCE_wORKS

2010-03-19 01:33:06

"Sex" your awsome. you astound me with your awsomeness. YohoJo well i appreciate the input but you actually managed to make it longer. but i wont hold it against you. :)

YoHoJo

2010-03-19 02:45:06

:p Hah, you're right, but remember shortness doesn't always necessarily mean an optimized script!