Thread Tools Display Modes
02-25-15, 08:07 AM   #1
Mercian
A Murloc Raider
Join Date: Apr 2012
Posts: 6
Debuff Filter - need help in solve lua error

Hi guys,

first I want to say: I'm totally new to LUA. I'm working with other scripting languages.
Getting this one LUA error is a pain in the ass for me and as the original author is not playing anymore I try to figure out the issue by myself.

Following the error it throws:

Error occured in: Global
Count: 1
Message: ..\AddOns\DebuffFilter\DebuffFilter.lua line 2279:
attempt to perform arithmetic on local 'BB' (a nil value)
Debug:
DebuffFilter\DebuffFilter.lua:2279: DebuffFilter_Frame_Update()
DebuffFilter\DebuffFilter.lua:1799:
DebuffFilter\DebuffFilter.lua:1796

When looking into the code the issue is caused by these lines of code:
Code:
			while texture do
				buffInGroup = sb.showAllBuffs
				frameitem.Comparisons["ismine"] = caster == "player";

				if not buffInGroup and sb.showAllNonRaiderBuffs and caster ~= nil then
					casterGUID = UnitGUID(caster);
					if casterGUID ~= nil then 
						BB = tonumber(casterGUID:sub(5,5), 16);
						maskedBB = BB % 8; -- x % 8 has the same effect as x & 0x7 on numbers <= 0xf
						-- mask with 0x7 to get: 0 for players, 1 for world objects, 3 for NPCs, 4 for permanent pets, 5 for vehicles.
						if maskedBB ~= 0 and maskedBB ~= 4 and maskedBB ~= 5 then
							buffInGroup = true
						end
					end	
				end
the line
Code:
maskedBB = BB % 8;
is throwing the error.

According to the local stack from the error the variables have the following values:
BB = nil
maskedBB = nil
caster = "target"

EDIT:
Additionally the variable:
casterGUID = "Creature-0-1467-1153-21838-79821-0000562487"

My first question is, what does this line mean:
frameitem.Comparisons["ismine"] = caster == "player";

I've not found any information in using "=" and "==" in this way.

Thanks a lot for any help

EDIT 2: Found out the reason:
casterGUID:sub(5,5) of casterGUID = "Creature-0-1467-1153-21838-79821-0000562487" cannot be converted to a number.
So why is this GUID not matching the description of http://www.wowwiki.com/API_UnitGUID?

Last edited by Mercian : 02-25-15 at 08:23 AM.
  Reply With Quote
02-25-15, 08:37 AM   #2
Elkano
A Flamescale Wyrmkin
 
Elkano's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2005
Posts: 131
just a quick reply:
1. it's Lua, not LUA
2. "a = b == c" is the same as "a = (b == c)", so a = true if b equals c
3. regarding your error:

It's caused by this statement: BB = tonumber(casterGUID:sub(5,5), 16);
What it does is trying to convert the 5th char in the string to a number by interpreting it as a hexadecimal value.
Since your string starts with "creature", the 5th char is a t which has no hexadecimal meaning.

Why does this happen?
Well, GUID changed for WoW 6.x (see: http://wow.gamepedia.com/GUID, old: http://wow.gamepedia.com/index.php?t...&oldid=2939882 ).

Fix: adapt the code to the new GUID format (e.g. get the first part and match it against the desired values)
__________________
This posting is made of 100% recycled electrons.
  Reply With Quote
02-25-15, 08:57 AM   #3
Mercian
A Murloc Raider
Join Date: Apr 2012
Posts: 6
oh sorry...will remember to name it "lua"

regarding you links: perfect, this is explaining the error.

New question:
Regarding your links the result of UnitGUID() is different between player and creatures. So instead of doing the masking I need to do a substring of the first part (start till first occurance of "-") to identify the unittype, right?

So synthax would be like

if casterGUID ~= nil then
BB =casterGUID:sub(5,casterGUID:find("-"))
if BB == "Creature"
buffInGroup = true
end
end

Is the type "Creature" also including Rare mobs? Because I saw an extra type "vignette" in your link.
  Reply With Quote
02-25-15, 10:52 AM   #4
Elkano
A Flamescale Wyrmkin
 
Elkano's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2005
Posts: 131
Never did much work with GUIDs myself, so I don't know which is used for what, sorry.

But regarding getting the first part of the string, your syntax for :sub is wrong (e.g. starts at 5th char and includes the dash).

You could try one of the following:
Code:
bb = strsplit("-", casterGUID) -- split string on dashes, assign the first resulting string to BB, discard rest
bb = strmatch(casterGUID, "^([^-]+)") -- get the longest sequence of non-dash characters starting at the beginning of the string
__________________
This posting is made of 100% recycled electrons.
  Reply With Quote
02-25-15, 12:06 PM   #5
Mercian
A Murloc Raider
Join Date: Apr 2012
Posts: 6
Originally Posted by Elkano View Post
Never did much work with GUIDs myself, so I don't know which is used for what, sorry.

But regarding getting the first part of the string, your syntax for :sub is wrong (e.g. starts at 5th char and includes the dash).

You could try one of the following:
Code:
bb = strsplit("-", casterGUID) -- split string on dashes, assign the first resulting string to BB, discard rest
bb = strmatch(casterGUID, "^([^-]+)") -- get the longest sequence of non-dash characters starting at the beginning of the string
Hi,

thanks for your suggestion.

But as UnitType can also be "Pet" it would not be the longest sequence of non-dash characters.
I will check if my idea is working
  Reply With Quote
02-25-15, 01:17 PM   #6
Mercian
A Murloc Raider
Join Date: Apr 2012
Posts: 6
btw...my solution is working. Thanks for the help.
  Reply With Quote
02-25-15, 01:57 PM   #7
Elkano
A Flamescale Wyrmkin
 
Elkano's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2005
Posts: 131
Does it really work or just not error? There's s slight difference between the two

also, if the unit type is "Pet", the GUID will be "Pet-0-...", so it's still the longest sequence of non-dash characters starting at the beginning of the string.
__________________
This posting is made of 100% recycled electrons.
  Reply With Quote
02-25-15, 08:18 PM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Mercian View Post
Is the type "Creature" also including Rare mobs? Because I saw an extra type "vignette" in your link.
Vignettes are the skulls and other icons that appear on your minimap for rare creatures, treasures, etc. The GUID for a vignette -- even if it's marking the location of a creature -- includes information for use with the C_Vignettes functions, and does not include the NPC ID or other creature-specific information.
__________________
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
02-26-15, 02:00 AM   #9
Mercian
A Murloc Raider
Join Date: Apr 2012
Posts: 6
Originally Posted by Elkano View Post
Does it really work or just not error? There's s slight difference between the two

also, if the unit type is "Pet", the GUID will be "Pet-0-...", so it's still the longest sequence of non-dash characters starting at the beginning of the string.

My solution is working. I had issues on my warlock, that a buff was not updated correctly. I tested yesterday with several chars, checking buffs and debuffs of player and creatures.

Additionally in first try I forgot the "then" after an if condition...the frames were not displayed at all (without showing an lua error). After correcting this the frames were displayed correctly and no lua error was displayed.

Is there a way to do some kind of debugging? To know the result of my code?

Vignettes are the skulls and other icons that appear on your minimap for rare creatures, treasures, etc. The GUID for a vignette -- even if it's marking the location of a creature -- includes information for use with the C_Vignettes functions, and does not include the NPC ID or other creature-specific information.
Thanks for clarification. Then I don't need this type
  Reply With Quote
02-26-15, 04:11 AM   #10
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Mercian View Post
Is there a way to do some kind of debugging? To know the result of my code?
Yes. Just add print statements where you want to see what's happening in your code. Here's an example from one of my own addons:

https://github.com/Phanx/ShieldsUp/b.../Core.lua#L174

As it proceeds through the logic, at key points it prints out what it's doing and/or the values of certain variables. These messages appear in the chat frame so you can see exactly what's going on.

Just don't forget to comment out or remove these debugging messages when you're done, though, especially if you plan to publish your addon. You can see in my code that many of the messages are already commented out, but some are still "live" since the addon is currently being rewritten and tested.
__________________
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
02-26-15, 06:21 AM   #11
Mercian
A Murloc Raider
Join Date: Apr 2012
Posts: 6
Thanks a lot, will proof my solution with this.

As this is not my addon I suggested the solution to the author and will keep the changes only on my local copy.

I was so frustrated due to the errors and not working display that I tried to find the issue by myself.

As I said the original author is not playing anymore. He has given author rights to another user who requested them, but last information was, that he/she has also no experience using lua so it might take a while to solve the issue. So I did it myself and posted the solution.

Thanks so far for all the help
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Debuff Filter - need help in solve lua error

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