SRL Archive - Help and Support

Compass ?'s


Junior

2007-02-23 23:23:00

I dont know why this happens, but its kinda weird. When I call MakeCompass('');, sometimes it doesn't rotate the compass at all and just carries on to the next procedure. Why does it do that? And also, Sometimes I get a error wich says "Error detecting compass angle" and it terminates the script, Why does that happen? Im not the only one who is seeing these problems when using my script, and I have no clue on how to fix them or even what the problem is. Sorry if this is in the wrong section, but I didn't know where else to post this.

Boreas

2007-02-23 23:32:08

I did some experiments and posted on a thread somewhere. Basically the findcompassangle thinks a fairly wide range is north, so it doesn't move. A way around it is to make it go south first, then north. Or write your own.

Junior

2007-02-23 23:39:49

The compass is originally south though, and I want it to rotate until it hits north, but as I said sometimes it doesnt turn the compass… Ill see what I can do about writing my own lol :stirthepot:

pwnaz0r

2007-02-23 23:49:08

lol yeah thats what happens to me :p
I usually like call it a few times

Boreas

2007-02-23 23:50:40

Hmm the compass needs work. However it's probably better to slowly ween yourself off compass dependency when walking, as jagex will eventually screw it up and we will have to walk without it anyway.

Junior

2007-02-24 00:08:27

Bores ill take that into consideration, but wouldnt moving the compass at all make it seem like im autoing? This sounds like a bigger problem then I expected it to be.

Boreas

2007-02-24 00:10:15

Good point. Yea I guess you gotta get it working.

tarajunky

2007-02-24 00:15:39

FindCompassAngle searches a circle around the compass anchor point until it sees the red color at the tip of the compass pointer. It's possible that the sine/cosine algorithm could skip a pixel or two as it's searching, causing it to miss the pointer color, but I've never exhaustively tested it.

It starts by searching a circle with a radius greater than the compass point should be and then searches progressively smaller circles until it finds the tip. If it searches all those circles without finding the tip color then it will give you the "could not find compass angle" error.

I've never seen that error happen, myself. I don't think the screen brightness affects the color its searching for. If you want to skip FindCompassAngle, just rename a copy of MakeCompass in your script without that command and have it rotate randomly left or right.

Junior

2007-02-25 00:16:12

And I forgot to post this, but when it doesnt rotate the compass and I get that error, something happenes with my screen. I dont think I can explain this but when it doesnt rotate the MS, I cant rotate it myself either. In other words my keyboard doesnt work, and this only happens when it doesnt rotate the compass, understand? To stop this I have to pause or stop the script, minimize the window, bring it back up again and my keyboard works again.

tarajunky

2007-02-25 01:05:35

Hmm. Sounds like your client window is losing focus somehow…

Perhaps you could add an ActivateClient command before all your MakeCompass commands and see if that fixes the problem.

If the error is reproducible you might be able to test it, otherwise it's kind of hard to know if it helps or not.

ruler

2007-02-27 04:03:11


public int getCompass() throws InterruptedException {
RGB red = new RGB(159, 12, 14);
XY t1 = null, t2 = null, t3 = null;
t1 = findXYspiral(
getColorArray2d(),
red,
Areas.COMPASS,
new Rectangle[] { Areas.COMPASSEXCLUDE, Areas.COMPASSEXCLUDE2 },
10, 10, 10);
if (t1 != null) {
t2 = findXYspiral(getColorArray2d(), red, Areas.COMPASS,
new Rectangle[] { Areas.COMPASSEXCLUDE,
Areas.COMPASSEXCLUDE2,
new Rectangle(t1.x - 3, t1.y - 3, 6, 6) }, 10, 10,
10);
if (t2 != null) {
t3 = findXYspiral(getColorArray2d(), red, Areas.COMPASS,
new Rectangle[] { Areas.COMPASSEXCLUDE,
Areas.COMPASSEXCLUDE2,
new Rectangle(t1.x - 3, t1.y - 3, 6, 6),
new Rectangle(t2.x - 3, t2.y - 3, 6, 6) }, 10,
10, 10);
if (t3 != null) {
return compassHelper(t1, t2, t3);
}
}
}
warn("getCompass() can not be done");
return -1;
}

private int compassHelper(XY xy1, XY xy2, XY xy3)
throws InterruptedException {
XY CompassCenter = new XY(566, 20);
xy1 = new XY(xy1.x - CompassCenter.x, CompassCenter.y - xy1.y);
xy2 = new XY(xy2.x - CompassCenter.x, CompassCenter.y - xy2.y);
xy3 = new XY(xy3.x - CompassCenter.x, CompassCenter.y - xy3.y);
XY reversePoint = null;
if (distanceDouble(xy1, xy3) > distanceDouble(xy2, xy3)
&& distanceDouble(xy1, xy3) > distanceDouble(xy1, xy2)) {
reversePoint = xy2;
} else if (distanceDouble(xy2, xy3) > distanceDouble(xy2, xy1)
&& distanceDouble(xy2, xy3) > distanceDouble(xy1, xy3)) {
reversePoint = xy1;
} else if (distanceDouble(xy1, xy2) > distanceDouble(xy2, xy3)
&& distanceDouble(xy1, xy2) > distanceDouble(xy1, xy3)) {
reversePoint = xy3;
}
if (reversePoint != null) {
int degrees = (int) Math.toDegrees(Math.atan2(reversePoint.y,
reversePoint.x));
degrees = shiftDegrees(degrees, 90);
return degrees;
} else {
//never has happened
warn("compassHelper() can not be done");
return -1;
}
}

/**
* Currently accurate within 5 degrees or less. Report bugs.
*
* @author GenoDemon
* @param degrees
* @throws InterruptedException
*/
public void setCompass(int degrees) throws InterruptedException {
setCompass(degrees, 0, 10);
}

public void setCompass(int degreeGoal, int attempt, int maxAttempt)
throws InterruptedException {
degreeGoal = shiftDegrees(degreeGoal, 0);
attempt++;
if (attempt >= maxAttempt)
return;
int varience = 5 * attempt / maxAttempt;

int currentCompass = getCompass();
int diff = degreeDifference(currentCompass, degreeGoal);
debug("[Compass Debug] Going to:" + degreeGoal + " from:"
+ currentCompass + " diff=" + diff);
if (Math.abs(diff) > varience) {
int millsecs;
if (Math.abs(diff) < 5) {
if (diff > 0)
millsecs = random(50, 75);
else
millsecs = -1 * random(50, 75);
} else {
millsecs = diff * random(9, 14);
}
if (millsecs > 0) {
SendKey(KeyEvent.VK_RIGHT, millsecs);
sleep(millsecs + 10);

} else {
millsecs *= -1;
SendKey(KeyEvent.VK_LEFT, millsecs);
sleep(millsecs + 10);
}
sleep(defaultmaxAgeInMillisecs+20);
int currentCompass2 = getCompass();
int diff2 = degreeDifference(currentCompass, degreeGoal);
debug("[Compass Debug] Current: " + currentCompass2 + " Want: "
+ degreeGoal + " Missed by: " + diff2);
if (Math.abs(diff2) > varience)
setCompass(degreeGoal, attempt, maxAttempt);
}
}

public int degreeDifference(int degrees1, int degrees2) {
degrees1+=360;
degrees2+=360;
int diff1 = degrees1-degrees2;
int diff2 = 360-diff1;
if(Math.abs(diff1) > Math.abs(diff2)){
return diff2;
}
return diff1;
}

public int shiftDegrees(int degrees, int shiftBy) {
degrees += shiftBy;
while (degrees <= -180) {
degrees += 360;
}
while (degrees > 180) {
degrees -= 360;
}
while (degrees <= -180) {
degrees += 360;
}
while (degrees > 180) {
degrees -= 360;
}
return degrees;
}

Avaphi

2007-02-27 10:54:48

How well does that work ruler?

ruler

2007-02-27 18:36:16

From: Avaphi
How well does that work ruler?

it is always correct and never fails.