Results 1 to 6 of 6

Thread: How to use this procedure?

  1. #1
    Join Date
    May 2008
    Posts
    35
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default How to use this procedure?

    i decided to look at the includes inside the srl folder and i cant understand how to implement them, do i unclude the whole piece of code or just the first line? if i include the whole thing, can someone explain it to me? as i understand the first line but am still blurry on how tolerance is measured. what does 1 tolerance mean?

    I assume that functions are used the same way as procedures, if so whats the difference?
    Code:
    function AutoColorThis(Bitmap, MaxTol, X1, Y1, X2, Y2: Integer): Integer;
    var
      lTol, Ax, Ay: Integer;
    begin
      Result := 0;
      repeat;
        if (FindTransparentBitmapTolerance(Bitmap, Ax, Ay, clBlack, X1, Y1, X2, Y2, lTol)) then
        begin
          Result := GetColor(Ax, Ay);
          Exit;
        end;
        lTol := lTol + 5;
      until (lTol >= MaxTol);
      srl_Warn('AutoColorThis', 'The Color was not found', warn_Warning);
      WriteLn('Color NOT found.');
    end;
    I assume that functions are used the same way as procedures. what is the difference between the 2 of them?

  2. #2
    Join Date
    Feb 2007
    Posts
    3,616
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    procedures just execute the code inside of them. Functions return a value (Example: FindColor returns true if it found the color, so you can use an if/then to know if a color was found).

    AutoColorThis is used with bitmaps. You send the function a bitmap, the tolerance, and where to look for it. It returns (results in) the color it finds. Usage:

    SCAR Code:
    var color, bmp: Integer;

    bmp := //Whatever the bitmap is.
    color := AutoColorThis(bmp,10,MSX1,MSY1,MSX2,MSY2);

    Understand? If you have any more questions just let me know.

  3. #3
    Join Date
    Jul 2008
    Location
    Canada
    Posts
    1,612
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Like for the auto color thing you could do:

    if AutoColorThis(bitmap, 25, MSX1, MSY1, MSX2, MSY2) > 0 then

    I wouldn't do that, but thats an example of how a function that returns an int value could be used.
    For example, if you stored it in a variable so like:
    xt := autocolorthis
    if FindColor(the color could b xt.
    Since it saves the value, not sure i that one works but its an example of how functions can be used.

  4. #4
    Join Date
    May 2008
    Posts
    35
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    thanks to both of you, you helped me alot but i still dont fully understand tolerance. if i set the tolerance to 1 how tolerant would that be? and if i was looking for say, a shark in your inventory what should the tolerance be?

  5. #5
    Join Date
    Feb 2007
    Posts
    3,616
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    10 is probably a good tolerance.

    Tolerance is simply the amount of lenience a color or bitmap can have. 0 means it has to be exactly as the bitmap/color you picked. 1 is very close...etc.

    You could do like:

    SCAR Code:
    var i: Integer;

    for i := 1 to 15 do //Keep incrementing the i by 1 until bitmap is found (maximum 15)
    begin
      if(FindBitmapToleranceIn(shark,x,y,MIX1,MIY1,MIX2,MIY2,i))then //Use i as the tolerance for finding the bitmap
      begin
        MMouse(x,y,4,4);
        if(IsUpText('Shark'))then
          break;
      end;
    end;
    GetMousePos(x,y);
    Mouse(x,y,0,0,false); //Right click the shark


    You could also auto color the bitmap once it's found, and then do a FindColor if you want.
    Last edited by JAD; 08-27-2009 at 06:15 AM.

  6. #6
    Join Date
    May 2008
    Posts
    35
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    i get it now. thank very much =]

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
  •