SRL Archive - OSR Help

Math Error


King

2013-03-15 17:32:18

function AtBank: boolean;
begin
findSymbol(x, y, Symbol_Bank);
Result := (distance(x, y, 643, 84) <= 2);
end;
I keep getting a math error at the distance function, any ideas? Im trying to find the distance between my player on the MM and the Symbol, to determine my location, it occasionally gives the error.

rj

2013-03-15 19:51:11

Maybe it can't find the DTM so it assume the values are 0? Not sure though

Le Jingle

2013-03-15 22:33:37

You could have the bank symbol be in one of four different quadrants (i - iv) of x, y coords resulting from finding symbol. This can result you with retrieving x2, y2 being less than the symbol's coordinates.

Thus, taking a square root of a negative number is the likely cause of your math number (considering an imaginary coordinate on the MiniMap won't do you much good here).

I'd recommend taking the absolute values first before finding distance.

-Lj

Le Jingle

2013-03-16 00:24:57

From: core
No, this is incorrect. This distance formula uses square roots. The square of a negative and a positive number are the same.

distance = sqrt( (x2 - x1)^2 + (y2 - y1)^2 )

Using the absolute values of the coordinates would give your incorrect results.

The distance between -2,-2 and 2,2 is not 0.

You should put in the actual coordinates into distance(x1,y1,x2,y2). This will give you the answer you need.


You're right, I honestly have no idea how I can up with my last reply. Guess it's been a long week :closedeyes:

King

2013-03-22 20:17:18

From: core
No worries! I definitely know how that can feel… 10 hours of sleep in 3 nights due to midterms/projects.


Forgot to subscribe to this!!! Thankyou<3 I asked my FST teach, said the same thing :P