Thread Tools Display Modes
Prev Previous Post   Next Post Next
11-18-10, 11:56 AM   #1
Dawn
A Molten Giant
 
Dawn's Avatar
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 918
string length issue

I'm using tags for my oUF layout that abbreviate long names.

Code:
	local oldName = UnitName(unit)
	local newName = (string.len(oldName) > 14) and string.gsub(oldName, "%s?(.[\128-\191]*)%S+%s", "%1. ") or oldName
	
	if not UnitIsPlayer(unit) then
		return utf8sub(newName, 14, false)
	else
		return oldName
	end

Everything works fine, but on level up the following error can occur. It only seems to happen when the unit name contains letters like "Æ", "Ø" and the like.

(Line 47 is highlighted red, above.)
Code:
Message: Interface\AddOns\oUF_Slim\Slim_Tags.lua:47: bad argument #1 to 'len' (string expected, got nil)
Time: 11/18/10 18:43:03
Count: 1
Stack: [C]: in function `len'
Interface\AddOns\oUF_Slim\Slim_Tags.lua:47: in function `func'
Interface\AddOns\oUF\elements\tags.lua:595: in function `UpdateTag'
Interface\AddOns\oUF\elements\tags.lua:375: in function <Interface\AddOns\oUF\elements\tags.lua:370>

Locals: (*temporary) = nil
(*temporary) = "string expected, got nil"
What I do not get is why it happens on level up. Normally, you can switch through units with no matter what characters and the name always abbreviates/updates correctly.

Any idea how to fix it or maybe a workaround?
__________________
Rock: "We're sub-standard DPS. Nerf Paper, Scissors are fine."
Paper: "OMG, WTF, Scissors!"
Scissors: "Rock is OP and Paper are QQers. We need PvP buffs."

"neeh the game wont be remembered as the game who made blizz the most money, it will be remembered as the game who had the most QQ'ers that just couldnt quit the game for some reason..."

  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » string length issue


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