SRL Archive - OSR Help

Some help please..


King

2013-05-29 07:50:42

Okay so my main goal here is to use the MM to find a Oak Tree (all trees on the MS have the same top colours, but the MM symbol for Oaks is unique, at least in my area.) This function finds the Oaks perfectly, the only issue comes to when the Oak is chopped down and is no longer on the MS but is on the MM, so I want this when it cant find the uptext to find the DTM again, but I am lost at this point, it seems to get stuck just clicking the same area of tree (searching the same box) for the color then uptext when it isnt there. So I need it exit, then refind the DTM and look for it, then repeat every time it doesnt find it, but in my head this works, in real life it doesnt. :P

Video of what it does:

(Will upload tomorrow, tired as balls right now, probably part of my problem XD );

function ChopOaks: Boolean;
var
TPA: TPointArray;
ATPA, OakATPA: T2DPointArray;
i, L, OX, OY, Tries, tmpCTS: Integer;
Oak, OldOakPoint: TPoint;
OakTPA: TPointArray;
OakBox: TBox;
aFound: T2DExtendedArray;
begin
Tries := 0;
tmpCTS := GetColorToleranceSpeed;
if InvFull then
exit;
result := false;
OakMM := DTMFromString('mWAAAAHicY2FgYGBmgAB2IGYBYlYozQIVj1JlYND0ZGAwimEFYy6gmAgSZkTDIAAAb4oCgQ==');
MakeCompass('N');
if FindDTMsRotatedSE(OakMM, OakTPA, 633, 69, 679, 104, - Pi / 2, Pi / 2, Pi / 30, aFound) then
begin
FreeDTM(OakMM);
L := High(OakTPA) for i := 0 to L do
if GetArrayLength(OakTPA) >= 1 then
begin
Oak := MMtoMSEx(10, 0, OakTPA[i]);
SMART_ClearCanvas;
WriteDebug('Finding the tree');
begin
OakBox := IntToBox(Oak.x - 50, Oak.y - 50, Oak.x + 50, Oak.y + 50);
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.09, 0.88);
if FindColorsSpiralTolerance(MSCX, MSCY, TPA, 2446159, OakBox.x1, OakBox.y1, OakBox.x2, OakBox.Y2, 22) then
begin
WriteDebug('Clicking Tree');
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.02, 0.02);
ATPA := TPAtoATPAEx(TPA, 25, 25);
SortATPAFrom(ATPA, MiddleBox(OakBox));
if debug then
DebugATPA(ATPA, '');
L := High(ATPA) for i := 0 to L do
if GetArrayLength(ATPA[i]) >= 1 then
begin
MiddleTPAEx(ATPA[i], x, y);
MMouse(x, y, 2, 3);
if WaitUptext('Oak', 500) then
begin
ClickMouse2(false);
if WaitOption('Oak', 500) then
begin
SMART_ClearCanvas;
marktime(x);
wait(RandomRange(500, 600));
while IsChopping do
begin
FindNormalRandoms;
wait(RandomRange(50, 60));
end;
result := true;
exit;
end
else
begin
Inc(Tries);
WriteDebug(' Could not find Tree Uptext');
ColorToleranceSpeed(tmpCTS);
SetToleranceSpeed2Modifiers(0.02, 0.02);
end;
end
else
begin
WriteDebug(' Could not find Tree Uptext');
ColorToleranceSpeed(tmpCTS);
SetToleranceSpeed2Modifiers(0.02, 0.02);
Inc(Tries);
end;
end
else
begin
Inc(Tries);
WriteDebug('Could not find the chop option');
end;
end
else
begin
WriteDebug('Could not find the tree');
ColorToleranceSpeed(tmpCTS);
SetToleranceSpeed2Modifiers(0.02, 0.02);
Inc(Tries);
end;
end;
end;
end
else
begin
WriteDebug('Could not find the Oak MM symbol');
FreeDTM(OakMM);
TerminateScript;
end;
end;

P1ng

2013-05-29 08:32:38

I too am tired as all hell, but I'd suggest you need to throw some breaks or continues into your else statements

So if it doesn't find the colour/uptext it will jump back to the top of the loop where it is making boxes from your MMtoMSex points

I'd edit the function with my theory but I'm going to bed. Someone else might, or when you're awake enough you can probably make sense of what I'm trying to say.

EngageTheRage

2013-05-29 08:36:30

from what i have looked at so far, you have used i and L for a for loop, (for i := 0 to L do) and then within that for loop have another for loop using i and L again, and thay are changed, so if you go onto the next iteration, i have no idea where i and L will be …

also, just for ease of reading, i would recommend putting in begin and end; 's for all for/while loops and all if statements :)

ive almost finished going through :D

EDIT - sorry i didn't note what i changed, it's just cleaned it up and moved a few things added/removed some begin - end's, also changed the inner for loop variables:
function ChopOaks: Boolean;
var
TPA: TPointArray;
ATPA, OakATPA: T2DPointArray;
i, L, k, len, OX, OY, Tries, tmpCTS: Integer;
Oak, OldOakPoint: TPoint;
OakTPA: TPointArray;
OakBox: TBox;
aFound: T2DExtendedArray;
begin
Tries := 0;
tmpCTS := GetColorToleranceSpeed;
if InvFull then
begin
exit;
end;

result := false;
OakMM := DTMFromString('mWAAAAHicY2FgYGBmgAB2IGYBYlYozQIVj1JlYND0ZGAwimEFYy6gmAgSZkTDIAAAb4oCgQ==');
MakeCompass('N');

if FindDTMsRotatedSE(OakMM, OakTPA, 633, 69, 679, 104, - Pi / 2, Pi / 2, Pi / 30, aFound) then
begin
L := High(OakTPA);
for i := 0 to L do
begin
if GetArrayLength(OakTPA) >= 1 then
begin
Oak := MMtoMSEx(10, 0, OakTPA[i]);
SMART_ClearCanvas;
WriteDebug('Finding the tree');
OakBox := IntToBox(Oak.x - 50, Oak.y - 50, Oak.x + 50, Oak.y + 50);
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.09, 0.88);

if FindColorsSpiralTolerance(MSCX, MSCY, TPA, 2446159, OakBox.x1, OakBox.y1, OakBox.x2, OakBox.Y2, 22) then
begin
WriteDebug('Clicking Tree');
ATPA := TPAtoATPAEx(TPA, 25, 25);
SortATPAFrom(ATPA, MiddleBox(OakBox));

if debug then
begin
DebugATPA(ATPA, '');
end;

len := High(ATPA);
for k := 0 to len do
begin
if GetArrayLength(ATPA[k]) >= 1 then
begin
MiddleTPAEx(ATPA[k], x, y);
MMouse(x, y, 2, 3);
if WaitUptext('Oak', 500) then
begin
ClickMouse2(false);
if WaitOption('Oak', 500) then
begin
SMART_ClearCanvas;
marktime(x);
wait(RandomRange(500, 600));
while IsChopping do
begin
FindNormalRandoms;
wait(RandomRange(50, 60));
end;
result := true;
FreeDTM(OakMM);
ColorToleranceSpeed(tmpCTS);
SetToleranceSpeed2Modifiers(0.02, 0.02);
exit;
end else
begin
Inc(Tries);
WriteDebug(' Could not find Tree Uptext');
end;
end else
begin
WriteDebug(' Could not find Tree Uptext');
Inc(Tries);
end;
end else
begin
Inc(Tries);
WriteDebug('Could not find the chop option');
end;
end;
end else
begin
WriteDebug('Could not find the tree');
Inc(Tries);
end;
end;
end;
end else
begin
WriteDebug('Could not find the Oak MM symbol');
FreeDTM(OakMM);
TerminateScript;
end;
FreeDTM(OakMM);
ColorToleranceSpeed(tmpCTS);
SetToleranceSpeed2Modifiers(0.02, 0.02);
end;

King

2013-05-29 11:25:32

From: P1ng
I too am tired as all hell, but I'd suggest you need to throw some breaks or continues into your else statements

So if it doesn't find the colour/uptext it will jump back to the top of the loop where it is making boxes from your MMtoMSex points

I'd edit the function with my theory but I'm going to bed. Someone else might, or when you're awake enough you can probably make sense of what I'm trying to say.


From: EngageTheRage
from what i have looked at so far, you have used i and L for a for loop, (for i := 0 to L do) and then within that for loop have another for loop using i and L again, and thay are changed, so if you go onto the next iteration, i have no idea where i and L will be …

also, just for ease of reading, i would recommend putting in begin and end; 's for all for/while loops and all if statements :)

ive almost finished going through :D

EDIT - sorry i didn't note what i changed, it's just cleaned it up and moved a few things added/removed some begin - end's, also changed the inner for loop variables:
function ChopOaks: Boolean;
var
TPA: TPointArray;
ATPA, OakATPA: T2DPointArray;
i, L, k, len, OX, OY, Tries, tmpCTS: Integer;
Oak, OldOakPoint: TPoint;
OakTPA: TPointArray;
OakBox: TBox;
aFound: T2DExtendedArray;
begin
Tries := 0;
tmpCTS := GetColorToleranceSpeed;
if InvFull then
begin
exit;
end;

result := false;
OakMM := DTMFromString('mWAAAAHicY2FgYGBmgAB2IGYBYlYozQIVj1JlYND0ZGAwimEFYy6gmAgSZkTDIAAAb4oCgQ==');
MakeCompass('N');

if FindDTMsRotatedSE(OakMM, OakTPA, 633, 69, 679, 104, - Pi / 2, Pi / 2, Pi / 30, aFound) then
begin
L := High(OakTPA);
for i := 0 to L do
begin
if GetArrayLength(OakTPA) >= 1 then
begin
Oak := MMtoMSEx(10, 0, OakTPA[i]);
SMART_ClearCanvas;
WriteDebug('Finding the tree');
OakBox := IntToBox(Oak.x - 50, Oak.y - 50, Oak.x + 50, Oak.y + 50);
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.09, 0.88);

if FindColorsSpiralTolerance(MSCX, MSCY, TPA, 2446159, OakBox.x1, OakBox.y1, OakBox.x2, OakBox.Y2, 22) then
begin
WriteDebug('Clicking Tree');
ATPA := TPAtoATPAEx(TPA, 25, 25);
SortATPAFrom(ATPA, MiddleBox(OakBox));

if debug then
begin
DebugATPA(ATPA, '');
end;

len := High(ATPA);
for k := 0 to len do
begin
if GetArrayLength(ATPA[k]) >= 1 then
begin
MiddleTPAEx(ATPA[k], x, y);
MMouse(x, y, 2, 3);
if WaitUptext('Oak', 500) then
begin
ClickMouse2(false);
if WaitOption('Oak', 500) then
begin
SMART_ClearCanvas;
marktime(x);
wait(RandomRange(500, 600));
while IsChopping do
begin
FindNormalRandoms;
wait(RandomRange(50, 60));
end;
result := true;
FreeDTM(OakMM);
ColorToleranceSpeed(tmpCTS);
SetToleranceSpeed2Modifiers(0.02, 0.02);
exit;
end else
begin
Inc(Tries);
WriteDebug(' Could not find Tree Uptext');
end;
end else
begin
WriteDebug(' Could not find Tree Uptext');
Inc(Tries);
end;
end else
begin
Inc(Tries);
WriteDebug('Could not find the chop option');
end;
end;
end else
begin
WriteDebug('Could not find the tree');
Inc(Tries);
end;
end;
end;
end else
begin
WriteDebug('Could not find the Oak MM symbol');
FreeDTM(OakMM);
TerminateScript;
end;
FreeDTM(OakMM);
ColorToleranceSpeed(tmpCTS);
SetToleranceSpeed2Modifiers(0.02, 0.02);
end;


Thanks guys, I got what the problem was, I was resetting my variables in the for do statements by not using different ones :P

Repped Engage and P1ng <3

EngageTheRage

2013-05-29 12:00:29

no worries, glad you got it sorted :D

wantonman

2013-05-29 13:16:53

nice scripting standards by the way… my eyes just fell asleep they were soo soft

King

2013-05-29 20:20:57

From: wantonman
nice scripting standards by the way… my eyes just fell asleep they were soo soft


I dont know which of us you mean, but yes EngageTheRage does have good standards :D