Thread Tools Display Modes
08-10-14, 09:13 AM   #1
ObbleYeah
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 210
casting bar: attempt to perform arithmetic

Code:
\castbar.lua:77: attempt to perform arithmetic on local "endTime" (a nil value)
happens when i'm casting and my target is channeling simultaneously.

Lua Code:
  1. --
  2.  
  3. -- latency ------------------------------------------------------------------------------
  4.  
  5.     local function findCastLatency(self)
  6.         local latency = self.latency
  7.         local width = self:GetWidth()
  8.         local _, _, _, ms = GetNetStats()
  9.  
  10.         if (ms~=0) then
  11.             local safeZonePercent = (width/self.max) * (ms/1e5)
  12.             if(safeZonePercent > 1) then
  13.                 safeZonePercent = 1
  14.             end
  15.             latency:SetWidth(width*safeZonePercent)
  16.             latency:Show()
  17.         else
  18.             latency:Hide()
  19.         end
  20.     end
  21.  
  22.     local function cbLatency(self, event, ...)  
  23.         local name, _, text, texture, startTime, endTime, castid, interrupt        
  24.         local unit, spellName, _, id, spellId = ...
  25.         local cb = self.latency    
  26.        
  27.         -- we don't want to look at any castbars but our own
  28.         if (self.unit~="player") then return end
  29.    
  30.         if (event=="UNIT_SPELLCAST_START") then
  31.             if (cb) then
  32.                 name, _, text, texture, startTime, endTime, _, castid, interrupt = UnitCastingInfo(self.unit)
  33.                 endTime = endTime / 1e3
  34.                 startTime = startTime / 1e3
  35.                 local max = endTime - startTime
  36.                 self.max = max
  37.                 cb:ClearAllPoints()
  38.                 cb:SetPoint("TOP")
  39.                 cb:SetPoint("BOTTOM")
  40.                 cb:SetPoint("RIGHT")
  41.             end            
  42.             findCastLatency(self)
  43.         elseif (event=="UNIT_SPELLCAST_CHANNEL_START") then
  44.             if (cb) then
  45.                 name, _, text, texture, startTime, endTime, _, castid, interrupt = UnitChannelInfo(self.unit)
  46.                 endTime = endTime / 1e3
  47.                 startTime = startTime / 1e3
  48.                 local max = endTime - startTime
  49.                 self.max = max
  50.                 self.casting = nil
  51.                 self.castid = nil
  52.                 cb:ClearAllPoints()
  53.                 cb:SetPoint("TOP")
  54.                 cb:SetPoint("BOTTOM")
  55.                 cb:SetPoint("LEFT")
  56.             end            
  57.             findCastLatency(self)
  58.         elseif ((event=="UNIT_SPELLCAST_STOP") or (event=="UNIT_SPELLCAST_CHANNEL_STOP") or  (event=="UNIT_SPELLCAST_FAILED") or (event=="UNIT_SPELLCAST_INTERRUPTED")) then
  59.             if (not self.casting and not self.channeling) then
  60.                 cb:Hide()
  61.                 self.queuezone:Hide()
  62.             end
  63.         end
  64.     end
  65.      
  66.     hooksecurefunc("CastingBarFrame_OnEvent", cbLatency)

line 77 is the UnitChannelInfo endTime. What's causing this?

Last edited by ObbleYeah : 08-10-14 at 09:15 AM.
  Reply With Quote
08-10-14, 09:53 AM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Try adding some debug prints to see what's going on:

Code:
if not endTime then
    print(event, unit, name, text, startTime, endTime)
end
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
08-10-14, 10:42 AM   #3
ObbleYeah
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 210
w/ that script at the start of the function:



w/ that script in the UNIT_SPELLCAST_START event:



& in the UNIT_SPELLCAST_CHANNEL_START:



+ the last one also spat out this error

Code:
1x FrameXML\UnitFrame.lua:173: script ran too long
FrameXML\UnitFrame.lua:173: in function "UnitFramePortrait_Update"
FrameXML\UnitFrame.lua:163: in function "UnitFrame_Update"
FrameXML\TargetFrame.lua:117: in function "TargetFrame_Update"
FrameXML\TargetFrame.lua:159: in function "OnEvent"
FrameXML\UnitFrame.lua:674: in function <FrameXML\UnitFrame.lua:672>
<in C code>
<string>:"CAMERAORSELECTORMOVE":4: in function <string>:"CAMERAORSELECTORMOVE":1
So I assume it's the channeling event that's being influenced somewhere beforehand?
  Reply With Quote
08-10-14, 12:26 PM   #4
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
wowwiki states "Received for party/raid members as well as the player" for UNIT_SPELLCAST_CHANNEL_START. Assuming this is still correct the return value of UNIT="target" seems to be strange.

Is this a castbar for party/raid units? Or for a target frame?

Did you test that with a party member as a target?

Maybe UNIT_SPELLCAST_CHANNEL_START triggers for target but just returns nothing if target isn't a party member? Can't test this.
  Reply With Quote
08-10-14, 12:34 PM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
You need to put the print statement somewhere after the variables you're printing in it are assigned values. Otherwise, of course they're all going to be nil.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
08-10-14, 12:40 PM   #6
ObbleYeah
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 210
  Reply With Quote
08-10-14, 12:50 PM   #7
ObbleYeah
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 210
Originally Posted by Duugu View Post
Is this a castbar for party/raid units? Or for a target frame?
Neither, it's for the player castbar - just adding a latency safe zone to the end of the default one.

I hadn't even realised party and raid units might be further muddying the waters, though I'd say the error is clearly based upon some cross-pollution of the player and target. It's an easily replicable error; just cast when the target is channeling. I will see what happens when i target a party member channeling a spell though.

edit: same result when targeting a party member w/o any other variation. Also getting no print returns at all when I put them in the right place, so i guess they're passing correctly?

Last edited by ObbleYeah : 08-10-14 at 01:00 PM.
  Reply With Quote
08-10-14, 12:53 PM   #8
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,323
UNIT_SPELLCAST_START and UNIT_SPELLCAST_CHANNEL_START aren't returning the values that are nil. Those are from UnitCastingInfo(). The code doesn't check if the event firing is for the player while it only runs for the player castbar. So it's asking UnitCastingInfo() to check the player when the target starts casting.



I would suggest replacing this line to be a little more robust:
Code:
if (self.unit~="player") then return end
-with-
Code:
if not UnitIsUnit(self.unit,"player") or not UnitIsUnit(unit,"player") then return; end
This will also proc on other bars if the unit happens to be pointing to the player (like target if you're targeting yourself).

Alternate:
Code:
if self.unit~="player" or not UnitIsUnit(self.unit,unit) then return; end
This will still restrict to the player castbar, but still checks if the event is firing for it.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 08-10-14 at 12:58 PM.
  Reply With Quote
08-10-14, 01:07 PM   #9
ObbleYeah
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 210
Thanks. Both versions give off the same error.

Code:
castbar.lua:48: Usage: UnitIsUnit("unit", "otherUnit")
which seems to only happen upon logging in/reloading the ui.

seems to have fixed the other issue though!

Last edited by ObbleYeah : 08-10-14 at 01:36 PM.
  Reply With Quote
08-10-14, 01:43 PM   #10
jeruku
A Cobalt Mageweaver
 
jeruku's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 223
What about checking to see if the casting unit is the castbars unit?

Lua Code:
  1. if unit ~= self.unit or unit ~= 'player' then return end
__________________
"I have not failed, I simply found 10,000 ways that did not work." - Thomas Edison

Last edited by jeruku : 08-11-14 at 10:58 AM. Reason: Forgot a step; OR not AND; parantheses? this isn't Java
  Reply With Quote
08-10-14, 01:47 PM   #11
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,323
Originally Posted by ObbleYeah View Post
Thanks. Both versions give off the same error.

Code:
castbar.lua:48: Usage: UnitIsUnit("unit", "otherUnit")
which seems to only happen upon logging in/reloading the ui.

seems to have fixed the other issue though!
I'm guessing it's unit that's throwing nil, we're already checking self.unit. Try either one of these depending on which you were using.
Code:
if not unit or not UnitIsUnit(self.unit,"player") or not UnitIsUnit(unit,"player") then return; end
Code:
if not unit or self.unit~="player" or not UnitIsUnit(self.unit,unit) then return; end




Originally Posted by jeruku View Post
What about checking to see if the casting unit is the castbars unit?

Lua Code:
  1. if (unit ~= self.unit) then return end
I try to include target if you happen to be targeting yourself. Same with including focus if you have focus on yourself.
With varying extents, this is what UnitIsUnit() is checking for.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 08-10-14 at 02:04 PM.
  Reply With Quote
08-10-14, 01:52 PM   #12
ObbleYeah
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 210
Yep, just came to the same realisation and fix too. Thanks for your help!
  Reply With Quote
08-10-14, 02:04 PM   #13
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,323
Originally Posted by ObbleYeah View Post
Code:
if (not self.casting and not self.channeling) then
I'm also seeing a problem with this line. Unlike the other events, you're not checking if your latency bar cb exists before attempting to hide it.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
08-10-14, 02:16 PM   #14
ObbleYeah
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 210
whoops, not sure why that's not included there already.
  Reply With Quote
08-11-14, 02:23 AM   #15
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by SDPhantom View Post
I try to include target if you happen to be targeting yourself. Same with including focus if you have focus on yourself. With varying extents, this is what UnitIsUnit() is checking for.
There's no reason to check UnitIsUnit here. If you're targeting yourself and cast a spell, then you'll get two events for the same spellcast -- one for the "player" unit, and one for the "target" unit. In this case, though, you only want to run your function once per spellcast (since you're not modifying the target castbar too) so you should just ignore the event for the "target" unit.

Code:
if unit ~= "player" or unit ~= self.unit then return end
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
08-11-14, 10:57 AM   #16
jeruku
A Cobalt Mageweaver
 
jeruku's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 223
Originally Posted by Phanx View Post
There's no reason to check UnitIsUnit here. If you're targeting yourself and cast a spell, then you'll get two events for the same spellcast -- one for the "player" unit, and one for the "target" unit. In this case, though, you only want to run your function once per spellcast (since you're not modifying the target castbar too) so you should just ignore the event for the "target" unit.

Code:
if unit ~= "player" or unit ~= self.unit then return end
Had a brain fart as I was in a hurry to leave, that is what I was trying to point out. And yes, in my haste I used AND instead of OR.
__________________
"I have not failed, I simply found 10,000 ways that did not work." - Thomas Edison
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » casting bar: attempt to perform arithmetic

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