WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   casting bar: attempt to perform arithmetic (https://www.wowinterface.com/forums/showthread.php?t=49614)

ObbleYeah 08-10-14 09:13 AM

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?

Phanx 08-10-14 09:53 AM

Try adding some debug prints to see what's going on:

Code:

if not endTime then
    print(event, unit, name, text, startTime, endTime)
end


ObbleYeah 08-10-14 10:42 AM

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?

Duugu 08-10-14 12:26 PM

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.

Phanx 08-10-14 12:34 PM

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. :p

ObbleYeah 08-10-14 12:40 PM


ObbleYeah 08-10-14 12:50 PM

Quote:

Originally Posted by Duugu (Post 295136)
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?

SDPhantom 08-10-14 12:53 PM

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.

ObbleYeah 08-10-14 01:07 PM

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!

jeruku 08-10-14 01:43 PM

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

SDPhantom 08-10-14 01:47 PM

Quote:

Originally Posted by ObbleYeah (Post 295145)
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




Quote:

Originally Posted by jeruku (Post 295148)
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.

ObbleYeah 08-10-14 01:52 PM

Yep, just came to the same realisation and fix too. Thanks for your help!

SDPhantom 08-10-14 02:04 PM

Quote:

Originally Posted by ObbleYeah (Post 295124)
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.

ObbleYeah 08-10-14 02:16 PM

whoops, not sure why that's not included there already.

Phanx 08-11-14 02:23 AM

Quote:

Originally Posted by SDPhantom (Post 295149)
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

jeruku 08-11-14 10:57 AM

Quote:

Originally Posted by Phanx (Post 295167)
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.


All times are GMT -6. The time now is 09:46 PM.

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