Results 1 to 8 of 8

Thread: Math Error

  1. #1
    Join Date
    Jun 2012
    Location
    Howell, Michigan
    Posts
    1,585
    Mentioned
    34 Post(s)
    Quoted
    553 Post(s)

    Default Math Error

    Simba Code:
    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.

  2. #2
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

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

  3. #3
    Join Date
    Feb 2012
    Location
    Wonderland
    Posts
    1,988
    Mentioned
    41 Post(s)
    Quoted
    272 Post(s)

    Default

    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

  4. #4
    Join Date
    Feb 2012
    Location
    Wonderland
    Posts
    1,988
    Mentioned
    41 Post(s)
    Quoted
    272 Post(s)

    Default

    Quote Originally Posted by core View Post
    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

  5. #5
    Join Date
    Jun 2012
    Location
    Howell, Michigan
    Posts
    1,585
    Mentioned
    34 Post(s)
    Quoted
    553 Post(s)

    Default

    Quote Originally Posted by core View Post
    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •