SRL Archive - Help and Support

There are some errors SCAR never meant you to figure out...


R0b0t1

2007-09-16 15:06:04

Yes! You've come to this thread to help me! Now, all you must do is look at this script and tell me WTF is wrong with it… I've gone over my checklist, but that did not work…. DAMN!


program New;

function AutoColorThisColor(ThisColor, PrefTol, Accry: Integer): Integer;
Var
DidFind: Boolean;
I, x1, y1, Cnt, FirstCorr: Integer;
X, Y, Z, Xc, Yc, Zc: Extended;
AX, AY, AZ: Array [1..20] of Extended;
ColorAr: Array [0..21] of Integer;
SkipAr: Array [0..19] of TPoint;
begin;
ColorAr[0]:= ThisColor;
For I:= 1 to 20 do
begin;
DidFind:= FindColorSkipCoordsTolerance(x1, y1, ThisColor, MSX1, MSY1, MSX2, MSY2, 50, SkipAr);
If (DidFind) Then
begin;
ColorAr[I]:= GetColor(x1, y1);
SkipAr[I].x:= x1;
SkipAr[I].y:= y1;
ColorToXYZ(ColorAr[I], AX[I], AY[I], AZ[I])
end;
end;
If (Accry > GetArrayLength(ColorAr)) Then
Accry:= GetArrayLength(ColorAr);
X:= AMaxE(AX);
Y:= AMaxE(AY);
Z:= AMaxE(AZ);
Xc:= X - AMinE(AX);
Yc:= Y - AMinE(AY);
Zc:= Z - AMinE(AZ);
FirstCorr:= 2;
For I:= 0 to (GetArrayLength(ColorAr) - 1) do
begin;
If (AX[I] > (Xc - PrefTol)) and (AX[I] < (X + PrefTol) and
(AY[I] > (Yc - PrefTol)) and (AY[I] < (Y + PrefTol) and
(AZ[I] > (Zc - PrefTol)) and (AZ[I] < (Z + PrefTol) Then
begin;
If (FirstCorr >= I) Then
FirstCorr:= I;
inc(Cnt);
end;
If (Cnt >= Accry) Then
Result:= XYZToColor(AX[FirstCorr], AY[FirstCorr], AZ[FirstCorr]);
else
Result:= 0;
end;

begin;
end.

Its on line 36… But you could correct the whole script :p.

pwnaz0r

2007-09-16 15:16:32

PrefTol is an integer, you cant subtract an extended from and integer or vice versa

EDIT: Btw here it is. Compiled, reformated for usefullness and restandardized( according to the reformatation)


program New;

function AutoColorThisColor(ThisColor, PrefTol, Accry: Integer): Integer;
Var
DidFind: Boolean;
I, x1, y1, Cnt, FirstCorr: Integer;
X, Y, Z, Xc, Yc, Zc: Extended;
AX, AY, AZ: Array [1..20] of Extended;
ColorAr: Array [0..21] of Integer;
SkipAr: Array [0..19] of TPoint;
begin;
ColorAr[0]:= ThisColor;
For I:= 1 to 20 do
begin;
DidFind:= FindColorSkipCoordsTolerance(x1, y1, ThisColor, MSX1, MSY1, MSX2, MSY2, 50, SkipAr);
If (DidFind) Then
begin;
ColorAr[i]:= GetColor(x1, y1);
SkipAr[i].x:= x1;
SkipAr[i].y:= y1;
ColorToXYZ(ColorAr[i], AX[i], AY[i], AZ[i])
end;
end;
If (Accry > GetArrayLength(ColorAr)) Then
Accry:= GetArrayLength(ColorAr);
X:= AMaxE(AX);
Y:= AMaxE(AY);
Z:= AMaxE(AZ);
Xc:= X - AMinE(AX);
Yc:= Y - AMinE(AY);
Zc:= Z - AMinE(AZ);
FirstCorr:= 2;
For I:= 0 to (GetArrayLength(ColorAr) - 1) do
begin;
If (AX[i] > (Xc - (StrToFloat(IntToStr(PrefTol)))))then
if (AX[i] < (X + (StrToFloat(IntToStr(PrefTol)))))then
if (AY[i] > (Yc - (StrToFloat(IntToStr(PrefTol)))))then
if (AY[i] < (Y + (StrToFloat(IntToStr(PrefTol)))))then
if (AZ[i] > (Zc - (StrToFloat(IntToStr(PrefTol)))))then
if (AZ[i] < (Z + (StrToFloat(IntToStr(PrefTol)))))then
begin;
If (FirstCorr >= I) Then
FirstCorr:= I;
inc(Cnt);
end;
If (Cnt >= Accry) Then
Result:= XYZToColor(AX[FirstCorr], AY[FirstCorr], AZ[FirstCorr])
else
Result:= 0;
end;
end;

begin;
end.

JuKKa

2007-09-16 15:52:48

ur missing an End;

pwnaz0r

2007-09-16 16:32:19

He is, im not

R0b0t1

2007-09-16 16:58:09

Pwnazor, the way you put the "if"s is counter productive… To much wasted space :\. (Means more time to compile…)


But I don't get it… Why shouldn't I be able to do math with to number types? Fffs.



Also, wouldn't adding "0.0" to each number be faster..? But then I could have just made PrefTol a floating point number… GaH!

EDIT: Pwnazor, it looks like you added an end to me…? Does and "if…else" statement, even with one command, need an end?

pwnaz0r

2007-09-16 17:17:18

No. but you used a semi colon after a line and it has to just say else.

wrong


Result:= XYZToColor(AX[FirstCorr], AY[FirstCorr], AZ[FirstCorr]);
else

right


Result:= XYZToColor(AX[FirstCorr], AY[FirstCorr], AZ[FirstCorr])
else

:P Your wrong about the if….then's statements being slower too. if you use and's, it checks every condition, whether one is false or not and if thens will cut out as soon as one statement is false.

R0b0t1

2007-09-16 17:37:55

You're also not following complete "standards". Even though mine are different, no one complains. But yours is.. Ehh.

But the way you're tier of if statements is, it just does the same thing.

This is how most programming languages do an if statement, logic wise: You put the condition, which must be a logical comparison that returns a boolean value. If there is more than one condition, it just mass computes it, thus almost exactly the same as yours but not having to use extra code to initiate the block.

Maybe someone super 1337 could tell me how close I am? You also just contradicted yourself on the if thing. You said as soon as one is false it cuts out… Isn't that the point with your way?

pwnaz0r

2007-09-16 17:47:04

From: r0b0t1
You're also not following complete "standards". Even though mine are different, no one complains. But yours is.. Ehh.

But the way you're tier of if statements is, it just does the same thing.

This is how most programming languages do an if statement, logic wise: You put the condition, which must be a logical comparison that returns a boolean value. If there is more than one condition, it just mass computes it, thus almost exactly the same as yours but not having to use extra code to initiate the block.

Maybe someone super 1337 could tell me how close I am? You also just contradicted yourself on the if thing. You said as soon as one is false it cuts out… Isn't that the point with your way?


I can explain to you (although i know you will find something wrong with it, as you do everything).


If Check1 and Check2 and Check3 and Check4 and Check5 then

  • Checks 1
  • Checks 2
  • Checks 3
  • Checks 4
  • Checks 5
  • finds if all statements are true
  • value of the statement is determined by the value of all being true



If Check1 then
if Check2 then
if Check3 then
if Check4 then
if Check5 then

  • Checks 1
  • if 1 is true, moves to 2
  • if 2 is true moves to 3
  • if 3 is true moves to 4
  • if 4 is true, moves to 5

and my scripting standards are the official standards. Who ever criticized them in the first place? No one

http://www.villavu.com/forum/showthread.php?t=3293

and i guess since you find the "smallest things" that are wrong with the procedure i was trying to help you with (most of which are actually right) and just try to criticize things such as scripting standards(sad you have to resort to this in first place) for no reason, then i will just keep my mouth shut the next time you have a problem. You don't see anyone else jumping in here to help you do you?

R0b0t1

2007-09-16 18:18:03

Defensive much?

The only problem in my script was that I did not know that you could not do math explicitly with floating points <> integers.

You're standards:

Result:= XYZToColor(AX[FirstCorr], AY[FirstCorr], AZ[FirstCorr]);
else

My standards:

If (DSAGGA) Then
Result:= SomeValu
else
Result:= OtherValu;

That one example, from directly above. I might be able to find others, but I conform to standards as well.

pwnaz0r

2007-09-16 18:30:46

all i did in that was take out the semi-colon so they were actually your standards…


Result:= XYZToColor(AX[FirstCorr], AY[FirstCorr], AZ[FirstCorr]);
else


is from your function all i did was change it to


Result:= XYZToColor(AX[FirstCorr], AY[FirstCorr], AZ[FirstCorr])
else

and im not being defensive, you have now found something wrong w/ two of my functions that have nothing wrong with them for no reason.