WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Errors in small coordinates addon. Would appreciate help. (https://www.wowinterface.com/forums/showthread.php?t=55751)

Lesteryoung 09-19-17 06:52 PM

Errors in small coordinates addon. Would appreciate help.
 
Lua Code:
  1. local CoordText = WorldMapFrame.BorderFrame.TitleText
  2.  
  3. local totalElapsed = 0
  4. WorldMapDetailFrame:HookScript('OnUpdate', function(self, elapsed)
  5.     if(totalElapsed > 0.1) then
  6.         if(WorldMapScrollFrame:IsMouseOver()) then
  7.             local scale = self:GetEffectiveScale()
  8.             local centerX, centerY = self:GetCenter()
  9.             local width, height = self:GetSize()
  10.             local x, y = GetCursorPosition()
  11.  
  12.             x = ((x / scale) - (centerX - (width / 2))) / width
  13.             y = (centerY + (height / 2) - (y / scale)) / height
  14.  
  15.             CoordText:SetFormattedText('%.0f , %.0f', x * 100, y * 100)
  16.             CoordText:SetTextColor(0, 1, 0)
  17.         else
  18.             local x, y = GetPlayerMapPosition('player')
  19.             CoordText:SetFormattedText('%.0f , %.0f', x * 100, y * 100)
  20.             CoordText:SetTextColor(1, 1, 0)
  21.         end
  22.  
  23.         totalElapsed = 0
  24.     else
  25.         totalElapsed = totalElapsed + elapsed
  26.     end
  27. end)

Is throwing this error, repeatedly.

Code:

25x Tweaks\Coordinates.lua:19: attempt to perform arithmetic on local 'x' (a nil value)
Tweaks\Coordinates.lua:19: in function <Tweaks\Coordinates.lua:4>

Locals:
self = WorldMapDetailFrame {
 0 = <userdata>
}
elapsed = 0.015000000596046
x = nil
y = nil
(*temporary) = <function> defined =[C]:-1
(*temporary) = WorldMapFrameTitleText {
 0 = <userdata>
}
(*temporary) = "%.0f , %.0f"
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = "attempt to perform arithmetic on local 'x' (a nil value)"
totalElapsed = 0.11200000345707
CoordText = WorldMapFrameTitleText {
 0 = <userdata>

Any ideas as to why? It seems to happen inside instances.

Thanks.

Kanegasi 09-19-17 07:08 PM

Quote:

Originally Posted by Lesteryoung (Post 325208)
Any ideas as to why? It seems to happen inside instances.

Patch 7.1 disabled the player location API in instances. Blizzard stated beforehand that it should fail silently, but they lied, like they usually do when PR and code mix, since no one involved with PR actually knows or understands code changes. Same thing happened in 7.2 when they protected friendly nameplates, which spat many errors as well.

If this is your code, you're going to have to account for any location-based API, such as coordinates or facing, returning nil values. If this is an addon you are using, update it.

Lesteryoung 09-19-17 07:31 PM

It's not my code, but from someone on here that I got a year or so ago.

I wouldn't really feel comfortable updating, I'd probably just break it more.

Ammako 09-19-17 07:35 PM

You could probably just replace line 19 with
lua Code:
  1. if x and y then CoordText:SetFormattedText('%.0f , %.0f', x * 100, y * 100) end

Kkthnx 09-19-17 07:46 PM

Could just check for it as well.

Lua Code:
  1. if x ~= 0 and y ~= 0 then
  2.     CoordText:SetFormattedText('%.0f , %.0f', x * 100, y * 100)
  3. else
  4.     CoordText:SetText('')
  5. end

Seerah 09-19-17 08:05 PM

Quote:

Originally Posted by Kanegasi (Post 325209)
Blizzard stated beforehand that it should fail silently, but they lied,

It does fail silently. It doesn't give an error when the function is called within instances, it just returns a nil value. The error happens when someone tries to do something they can't with a nil value.

Lesteryoung 09-19-17 08:30 PM

Thanks all. Appreciate the help.

semlar 09-19-17 08:51 PM

Quote:

Originally Posted by Kkthnx (Post 325212)
Could just check for it as well.

Lua Code:
  1. if x ~= 0 and y ~= 0 then
  2.     CoordText:SetFormattedText('%.0f , %.0f', x * 100, y * 100)
  3. else
  4.     CoordText:SetText('')
  5. end

This will throw an error if x and y are both nil.

Kkthnx 09-19-17 11:59 PM

Quote:

Originally Posted by semlar (Post 325215)
This will throw an error if x and y are both nil.

Weird, never had an issue with it since I had to change to it.

Seerah 09-20-17 01:56 PM

In an instance, nil is returned for the x and y coordinates.

Since nil ~= 0 ...

Lua Code:
  1. if x ~= 0 and y ~= 0 then   --> true
  2.     CoordText:SetFormattedText('%.0f , %.0f', x * 100, y * 100)   --> attempt to perform arithmetic on a nil value
  3. else
  4.     CoordText:SetText('')
  5. end


All times are GMT -6. The time now is 08:46 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI