Results 1 to 7 of 7

Thread: how can i shorten this procedure

  1. #1
    Join Date
    Jan 2007
    Location
    BC, Canada
    Posts
    66
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default how can i shorten this procedure

    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.

    Code:
    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;

  2. #2
    Join Date
    Dec 2006
    Location
    Houston, TX USA
    Posts
    4,791
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Make C: TIntegerArray and do a for do loop?

  3. #3
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default

    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 )

    SCAR Code:
    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

  4. #4
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

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

  5. #5
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    SCAR Code:
    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 .
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

  6. #6
    Join Date
    Jan 2007
    Location
    BC, Canada
    Posts
    66
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    "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.

  7. #7
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default

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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •