Quantcast
Errors in small coordinates addon. Would appreciate help. - WoWInterface
Thread Tools Display Modes
09-19-17, 06:52 PM   #1
Lesteryoung
A Cliff Giant
Join Date: Aug 2015
Posts: 76
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.
  Reply With Quote
09-19-17, 07:08 PM   #2
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 506
Originally Posted by Lesteryoung View Post
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.
  Reply With Quote
09-19-17, 07:31 PM   #3
Lesteryoung
A Cliff Giant
Join Date: Aug 2015
Posts: 76
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.
  Reply With Quote
09-19-17, 07:35 PM   #4
Ammako
A Frostmaul Preserver
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 256
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
  Reply With Quote
09-19-17, 07:46 PM   #5
Kkthnx
A Cobalt Mageweaver
 
Kkthnx's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2011
Posts: 245
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
__________________
Success isn't what you've done compared to others. Success is what you've done compared to what you were made to do.
  Reply With Quote
09-19-17, 08:05 PM   #6
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,765
Originally Posted by Kanegasi View Post
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.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
09-19-17, 08:30 PM   #7
Lesteryoung
A Cliff Giant
Join Date: Aug 2015
Posts: 76
Thanks all. Appreciate the help.
  Reply With Quote
09-19-17, 08:51 PM   #8
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,059
Originally Posted by Kkthnx View Post
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.
  Reply With Quote
09-19-17, 11:59 PM   #9
Kkthnx
A Cobalt Mageweaver
 
Kkthnx's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2011
Posts: 245
Originally Posted by semlar View Post
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.
__________________
Success isn't what you've done compared to others. Success is what you've done compared to what you were made to do.
  Reply With Quote
09-20-17, 01:56 PM   #10
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,765
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
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Errors in small coordinates addon. Would appreciate help.

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off