This site makes extensive use of JavaScript.
Please enable JavaScript in your browser.
Classic Theme
Thottbot Theme
Shortened Names
Post Reply
Return to board index
Post by
magemofo
Hiya guys.
I was wondering if there was a way to get shortened names using Pitbull4. By shortened I mean display only like the first 5 letters or so. I don't see an option for it under texts, and I have no idea how to create a lua for it myself. Any help would be great, thanks!
Post by
Wanderingfox
return "%s", strsub(Name(unit), 1, 5)
Should
do it... I haven't really worked with Luatexts that much, so my understanding of them is fairly basic.
Post by
HighFive
That will however break on multibyte UTF characters.
Here's a function that will do it properly:function(txt, num)
local len = 0
for i = 1, num do
local b = value:byte(len+1)
if not b then
break
elseif b <= 127 then
len = len + 1
elseif b <= 223 then
len = len + 2
elseif b <= 239 then
len = len + 3
else
len = len + 4
end
end
local val = value:sub(1, len)
return val
end
Post by
260392
This post was from a user who has deleted their account.
Post by
HighFive
I'm fairly sure it has the option to use both and from what I've heard, LuaTexts are quite <adjective>er.
Post by
Wanderingfox
I'm fairly sure it has the option to use both and from what I've heard, LuaTexts are quite <adjective>er.
tastier?
Post by
magemofo
Alright guys, thanks a bunch! I tried the first one, and it works!
@highfive, what are multibyte UTF characters? I'll try your way too if I ever run into those.
Post by
HighFive
Oh you inevitably will.The UTF-8 encoding is variable-width, with each character represented by 1 to 4 bytes.
So the first 128 characters (US-ASCII) need one byte. The next 1,920 characters need two bytes to encode. This includes Latin letters with diacritics and characters from Greek, Cyrillic, Coptic, Armenian, Hebrew, Arabic, Syriac and Tāna alphabets. Three bytes are needed for the rest of the Basic Multilingual Plane (which contains virtually all characters in common use). Four bytes are needed for characters in the other planes of Unicode, which include less common CJK characters and various historic scripts.Meaning ÐƙɭØɭ's name will not be truncated correctly.
Post by
260392
This post was from a user who has deleted their account.
Post by
magemofo
Ah thanks, that actually just happened to me in a ToC I was running. I'll use your code then :D
Just one more question, what do I change to get it to 3 or 4 letters instead of five? I decided that five was too long, so right now I'm using three.
Post by
HighFive
Going from Wanderingfox's example:local len = 0
for i = 1,
4
do
local b = value:byte(len+1)
if not b then
break
elseif b <= 127 then
len = len + 1
elseif b <= 223 then
len = len + 2
elseif b <= 239 then
len = len + 3
else
len = len + 4
end
end
local val = Name(unit):sub(1, len)
return "%s", valThe bolded 4 is the length.
Post by
Wanderingfox
Going from Wanderingfox's example:local len = 0
for i = 1,
4
do
local b = value:byte(len+1)
if not b then
break
elseif b <= 127 then
len = len + 1
elseif b <= 223 then
len = len + 2
elseif b <= 239 then
len = len + 3
else
len = len + 4
end
end
return "%s",
Name(unit):sub(1, len)
Bad highfive, extra variable is extra XP Also, is it just me or is 'value' never referenced anywhere else? Neither is i for that matter :P
Shouldn't it be:
local len = 0
for i = 1,
4
do
local b =
Name(unit)
:byte(
i
)
if not b then
break
elseif b <= 127 then
len = len + 1
elseif b <= 223 then
len = len + 2
elseif b <= 239 then
len = len + 3
else
len = len + 4
end
end
return "%s", Name(unit):sub(1, len)
Post by
magemofo
Hiya guys, sorry it took me so long to get back to you. I couldn't raid again until the weekend so I couldn't test it out.
Your codes work, HighFive and WanderingFox, but with multibyte characters there's always one more letter than I want. If I put in 3, then every name is reduced to 3 letters but multibyte characters get four letters. Is there a way to fix this, or are multibyte characters just weird like that?
Thanks!
Post by
HighFive
Cannot reproduce.
Post by
magemofo
Ok, here's a picture of what I mean. I don't usually fade my raid frames, but I was in a 40 man, so I had to fade them somewhat.
http://i46.tinypic.com/27y3jlw.jpg
Second column, three from the bottom. Rayl. The one below that one has it as well. Hell. There's four letters, while everyone else only has three. It's not a big deal, I was just wondering if it could be fixed. Thanks!
Post by
HighFive
I got what you meant. I just couldn't reproduce the bug, so I can't help you. Sorry.
Post by
windstrum
http://i46.tinypic.com/27y3jlw.jpg
Offtopic: Very pretty UI. I especially like what you've done with Pitbull and your minimap.
Post by
288048
This post was from a user who has deleted their account.
Post by
260392
This post was from a user who has deleted their account.
Post by
Wanderingfox
To clarify: A LuaText is basically a Lua function that returns some expected output. For example, the above LuaText is just a function without the function header or trailing end, and the exected output is a format string followed by the values to be used by said format string.
Post Reply
You are not logged in. Please
log in
to post a reply or
register
if you don't already have an account.