Results 1 to 9 of 9

Thread: Color Finding Function

  1. #1
    Join Date
    Jan 2007
    Posts
    248
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Color Finding Function

    Hey, I'm trying to get up a better color finding procedure, and I'm wondering, how to declare several different results from a Function.
    PHP Code:
    // AutoColorProcedure {note: color=iron}
    program colorfind;

    const
     
    rockcolor2305614//color of rock (will use this to auto color)
    var MineCol1,MineCol2,MineCol3,x,yinteger;
    Function 
    GetRockColor(MineCol1,MineCol2,MineCol3integer): integer
      begin
     
    if
     
    FindColorTolerance(x,y,rockcolor,10,5,416,336,2then
     GetColor
    (x+3,y+3) and GetColor(x-3,y-3)
    // This is where I do NOT kno what to put as a result

    end
    Near the end, I dont kno how to declare every different color I get as a result.
    If someone may, I'd like them to teach me how :P

  2. #2
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    Never mind, arrays are better, see Juniors post below

    Few ways to do this, none are really appealing.

    1.
    Make the variables where you want the answers to be global variables. Color1, Color2, etc as global vars. Then the autocolor function can set all of them. Not very elegant, but its easy.

    2.
    Slightly more elegant, but little harder. Make the autocolor procedure set the answers to variables of your choice.
    SCAR Code:
    procedure Autocolor (var answer1, answer2, answer3:integer);
    begin
      //do stuff
      answer1:=stuff
      etc
    end;
    autocolor(myvar1,myvar2,myvar3); will set the answers to those vars. Notice the var in the parameters. Findcolor/bitmap/dtms functions have this for the x,y location of the answer.

    3.
    Make it return a multiple branched type.
    SCAR Code:
    type 3Ints = record
    First,Second,Third :integer;
    end;

    var
    RockColors:3Ints;

    function AutoColorRock (parameters):3Ints;
    begin
      dostuff
      result.first:=stuff;
      result.second:=otherstuff;
      result.thrird:=morestuff;
    end;
    //main loop
    begin
    RockColors:=AutoColorRock(theparams);
    writeln(inttostr(rockcolors.first));
    writeln(inttostr(rockcolors.first));
    If you don't understand the type stuff then don't worry about it.

  3. #3
    Join Date
    Jul 2006
    Location
    NY
    Posts
    371
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Here you go, is this what your looking for?
    SCAR Code:
    // AutoColorProcedure {note: color = iron}
    program colorfind;

    const
     rockcolor = 2305614; //color of rock (will use this to auto color)
     
    var
     MineCol1, MineCol2, MineCol3, x, y: integer;

    function GetRockColor: array of integer;
    begin
      if (FindColorTolerance(x, y, rockcolor, 10, 5, 416, 336, 2)) then
      begin
        MineCol1 := GetColor(x + 3, y + 3);
        MineCol2 := GetColor(x - 3, y - 3);
        MineCol3 := GetColor(x, y);
        Result := ([MineCol1, MineCol2, MineCol3]);
      end else
        //Result := ([0, 0, 0]);    ****pick either of the 3...***
        //Result := ([0]);
        //Result := ([rockcolor, rockcolor, rockcolor]);
    end;

    begin
    end.

    EDIT: boreas' porcedures make more sense...

  4. #4
    Join Date
    Jan 2007
    Posts
    248
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Thanks alot for the help guys. It's REALLY helping alot.

  5. #5
    Join Date
    Jan 2007
    Posts
    248
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    PHP Code:
    // AutoColorProcedure {note: color=iron}
    program colorfind;

    const
     
    rockcolor2305614//color of rock (will use this to auto color)

    var MineCol: array [0..3of integer;
    a,x,yinteger;

    Function 
    GetRockColor(MineColinteger): integer;
      
    begin
     
    if
     
    FindColorTolerance(x,y,rockcolor,10,5,416,336,2then
      begin
     MineCol
    [0] := GetColor(x+3,y+3);
     
    MineCol[1] := GetColor(x-3,y-3);
     
    MineCol[2] := GetColor(x-3,y+3);
     
    MineCol[3] := GetColor(x+3,y-3);
        
    a:= 0 to 3;
    end
    Im getting an error now, dont kno why I need a semi colon, im pretty sure this is an obvious error im not seeing right now...

  6. #6
    Join Date
    Dec 2006
    Location
    UK
    Posts
    118
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Your problem is really simple.

    Code:
    FindColorTolerance(x,y,rockcolor,10,5,416,336,2) then
      begin
     MineCol[0] := GetColor(x+3,y+3);
     MineCol[1] := GetColor(x-3,y-3);
     MineCol[2] := GetColor(x-3,y+3);
     MineCol[3] := GetColor(x+3,y-3);
        a:= 0 to 3;
    should be
    Code:
    FindColorTolerance(x,y,rockcolor,10,5,416,336,2) then
      begin
     MineCol[0] := GetColor(x+3,y+3);
     MineCol[1] := GetColor(x-3,y-3);
     MineCol[2] := GetColor(x-3,y+3);
     MineCol[3] := GetColor(x+3,y-3);
      end;
    also you don't need the variable 'a' any more.

    THE NERD

  7. #7
    Join Date
    Jan 2007
    Posts
    248
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by the nerd View Post
    Your problem is really simple.

    Code:
    FindColorTolerance(x,y,rockcolor,10,5,416,336,2) then
      begin
     MineCol[0] := GetColor(x+3,y+3);
     MineCol[1] := GetColor(x-3,y-3);
     MineCol[2] := GetColor(x-3,y+3);
     MineCol[3] := GetColor(x+3,y-3);
        a:= 0 to 3;
    should be
    Code:
    FindColorTolerance(x,y,rockcolor,10,5,416,336,2) then
      begin
     MineCol[0] := GetColor(x+3,y+3);
     MineCol[1] := GetColor(x-3,y-3);
     MineCol[2] := GetColor(x-3,y+3);
     MineCol[3] := GetColor(x+3,y-3);
      end;
    also you don't need the variable 'a' any more.

    THE NERD
    Nope still get the problems

  8. #8
    Join Date
    Jul 2006
    Location
    NY
    Posts
    371
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Your calling variables more then twice and using them as paramaters in your procedure... I dont really understand what your doing.. But here it is, fixed.
    SCAR Code:
    // AutoColorProcedure {note: color=iron}
    program colorfind;

    const
     rockcolor= 2305614; //color of rock (will use this to auto color)

    //var MineCol: array [0..3] of integer;
    {a,}
    var
     x,y: integer;

    Function GetRockColor(MineCol: array [0..3] of integer): integer;
    var
     i: integer;
    begin
      if (FindColorTolerance(x, y, rockcolor, 10, 5, 416, 336, 2)) then
      begin
        MineCol[0] := GetColor(x+3,y+3);
        MineCol[1] := GetColor(x-3,y-3);
        MineCol[2] := GetColor(x-3,y+3);
        MineCol[3] := GetColor(x+3,y-3);
        i := Random(3) + 1;
        result := MineCol[i];
      end;
    end;
    //needed another end

    begin
    end.

    EDIT: Would this solve all your problems???
    SCAR Code:
    program New;
    {.include SRL/SRL.scar}

    const
     orecolor = 0;

    Function GetRockColor(rockcolor: integer): integer;
    var
     MineCol: array [0..3] of integer;
     i: integer;
    begin
      if (FindColorTolerance(x, y, rockcolor, 10, 5, 416, 336, 2)) then
      begin
        MineCol[0] := GetColor(x+3,y+3);
        MineCol[1] := GetColor(x-3,y-3);
        MineCol[2] := GetColor(x-3,y+3);
        MineCol[3] := GetColor(x+3,y-3);
        i := Random(3) + 1
        result := MineCol[i];
      end;
    end;

    //use like this

    procedure FindTheRock;
    var
     NewRockColor: integer;
    begin
     NewRockColor := GetRockColor(orecolor);
     if (FindColorSpiralTolerance(x, y, NewRockColor, msx1, msy1, msx2, msy2, 15)) then
       Writeln('Found');
    end;


    begin
      SetUpSRL;
      FindTheRock;
    end.

  9. #9
    Join Date
    Jan 2007
    Posts
    248
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Thanks, Hey if your still in the neighborhood, can you explain your first edit, the i =:random(3) +1
    *********************
    So say if I wanted to find a color, would it be looking for all the colors, and if it finds any of them, pick a random one of em? Correct me if im wrong. Thanks for the help man ++ rep

    EDIT, also, how would I call on that variable within a script.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. color finding
    By elobire in forum OSR Help
    Replies: 7
    Last Post: 12-15-2008, 09:03 PM
  2. Color Finding HELP!
    By P1nky in forum OSR Help
    Replies: 5
    Last Post: 02-23-2008, 03:17 AM
  3. Finding a color in the inv.
    By yanix in forum OSR Help
    Replies: 1
    Last Post: 01-30-2008, 09:51 PM
  4. color finding help
    By fORCE_wORKS in forum OSR Help
    Replies: 1
    Last Post: 11-09-2007, 11:18 AM
  5. Finding color in a box on MM?
    By hlstriker in forum OSR Help
    Replies: 7
    Last Post: 12-20-2006, 05:04 AM

Posting Permissions

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