View Full Version : Color Finding Function
TheGodfather
02-12-2007, 04:07 AM
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.
// 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(MineCol1,MineCol2,MineCol3: integer): integer
begin
if
FindColorTolerance(x,y,rockcolor,10,5,416,336,2) then
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
Boreas
02-12-2007, 04:33 AM
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.
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.
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.
Junior
02-12-2007, 04:38 AM
Here you go, is this what your looking for?
// 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...
TheGodfather
02-12-2007, 04:45 AM
Thanks alot for the help guys. It's REALLY helping alot.
TheGodfather
02-12-2007, 05:07 AM
// 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,x,y: integer;
Function GetRockColor(MineCol: integer): 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);
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...
the nerd
02-12-2007, 01:56 PM
Your problem is really simple.
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
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
TheGodfather
02-13-2007, 01:37 AM
Your problem is really simple.
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
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
Junior
02-13-2007, 01:55 AM
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.
// 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???
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.
TheGodfather
02-13-2007, 02:09 AM
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.
Powered by vBulletin® Version 4.2.1 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.