Thread Tools Display Modes
06-21-20, 06:16 AM   #1
Aur0r4
A Deviate Faerie Dragon
 
Aur0r4's Avatar
AddOn Compiler - Click to view compilations
Join Date: Feb 2010
Posts: 16
Combine two lua scripts

Hi guys,

Since I'm not good in Lua and my friends that are more into programming can't help me with that, this forum is my last hope.

I want to create a Lua-Text in PitBull Unit Frames, so that it shows this:

Name | HP %

Name should be in classcolor and HP% in HPColor.

So I have to separate scripts for that running:

Name | (ClassColor)
Code:
local r,g,b = ClassColor(unit)
return '|cff%02x%02x%02x%s|r %s%s%s|',r,g,b,Name(unit),Angle(AFK(unit) or DND(unit))
HP % (HPColor)
Code:
local s = Status(unit)
if s then
  return s
end
local cur,max = HP(unit),MaxHP(unit);
local hr,hg,hb=HPColor(cur,max);
return "|cff%02x%02x%02x%.0f|r" or "", hr,hg,hb,100*cur/max

I want to combine both scripts, so that I can display them in one lua-text. I need that, because otherwise I'm not able to center the text within the unitframe.

Can you help me with that?

Thanks!

edit:
We've tried that, but it isn't working:

Code:
local s = Status(unit)
if s then
  return s
end

local cur,max = HP(unit),MaxHP(unit);
local hr,hg,hb=HPColor(cur,max);
local r,g,b = ClassColor(unit)

return '|cff%02x%02x%02x%s|r %s%s%s| |cff%02x%02x%02x%.0f|r',r,g,b,Name(unit),Angle(AFK(unit) or DND(unit)), hr,hg,hb,100*cur/max
__________________
Aur0r4
Yuluria


See Yulu UI in action: here

F.A.Q.
  Reply With Quote
06-21-20, 11:06 AM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,857
I don't know PitBull so I'm not sure what Status() or Angle() is doing but my best guess is that it has more than 1 return and all but the first one are being cut off because it's no longer the last return in the format.

Without thinking too hard, maybe something like still treating the return as two strings:

Lua Code:
  1. local s = Status(unit)
  2. if s then
  3.   return s
  4. end
  5. local r,g,b = ClassColor(unit)
  6. local string1 = string.format('|cff%02x%02x%02x%s|r %s%s%s|', r,g,b,Name(unit),Angle(AFK(unit) or DND(unit)))
  7. local cur,max = HP(unit),MaxHP(unit);
  8. local hr,hg,hb=HPColor(cur,max);
  9. return string1 .. "|cff%02x%02x%02x%.0f|r" or "", hr,hg,hb,100*cur/max
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
06-21-20, 11:50 AM   #3
Aur0r4
A Deviate Faerie Dragon
 
Aur0r4's Avatar
AddOn Compiler - Click to view compilations
Join Date: Feb 2010
Posts: 16
Hi Fizzlemizz,

I have tried it but its not working correctly, I got this:



Do you have another idea? I will show your code to a friend, maybe he can fix it with your help.

Wish I would be better in programming
__________________
Aur0r4
Yuluria


See Yulu UI in action: here

F.A.Q.
  Reply With Quote
06-21-20, 11:57 AM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,857
Lua Code:
  1. local s = Status(unit)
  2. if s then
  3.   return s
  4. end
  5. local r,g,b = ClassColor(unit)
  6. local string1 = string.format('|cff%02x%02x%02x%s|r %s%s%s|', r,g,b,Name(unit),Angle(AFK(unit) or DND(unit)))
  7. local cur,max = HP(unit),MaxHP(unit);
  8. local hr,hg,hb=HPColor(cur,max);
  9. local string2 = string.format("|cff%02x%02x%02x%.0f|r" or "", hr,hg,hb,100*cur/max)
  10. return string1 .. string2

Someone here probably has a better solution.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
06-21-20, 02:01 PM   #5
Aur0r4
A Deviate Faerie Dragon
 
Aur0r4's Avatar
AddOn Compiler - Click to view compilations
Join Date: Feb 2010
Posts: 16
Thank you!
Sadly it is the same outcoming

Name |CFF00FF00100

Originally Posted by Fizzlemizz
Someone here probably has a better solution.
Hopefully or maybe its just a typo? But I don't see it...


Nevermind:

My girlfriend fixed it

Lua Code:
  1. local s = Status(unit)
  2. if s then
  3.   return s
  4. end
  5. local r,g,b = ClassColor(unit)
  6. local string1 = string.format('|cff%02x%02x%02x%s|r %s%s%s| ', r,g,b,Name(unit),Angle(AFK(unit) or DND(unit)))
  7. local cur,max = HP(unit),MaxHP(unit);
  8. local hr,hg,hb=HPColor(cur,max);
  9. local string2 = string.format('|cff%02x%02x%02x%.0f|r' or "", hr,hg,hb,100*cur/max)
  10. return string1 .. string2
__________________
Aur0r4
Yuluria


See Yulu UI in action: here

F.A.Q.

Last edited by Aur0r4 : 06-21-20 at 02:28 PM.
  Reply With Quote
06-21-20, 02:35 PM   #6
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
According to PitBull documentation, "LuaText" is simply fed into SetFormattedText and Angle returns three strings, which surrounds the input with "angle brackets" < >. If there's no input, in this case if the unit is not afk or dnd, it still returns three empty strings. Also, if you want to use the pipe character or the percent sign, you need to escape both.

Lua Code:
  1. local s=Status(unit)
  2. if s then return s end
  3. local cur,max=HP(unit),MaxHP(unit)
  4. local hr,hg,hb=HPColor(cur,max)
  5. return "|cff%02x%02x%02x%s|r %s%s%s || |cff%02x%02x%02x%.0f|r %%",ClassColor(unit),Name(unit),Angle(AFK(unit) or DND(unit)),hr,hg,hb,100*cur/max

I left a space between the health and the percent sign.

Edit: I didn't refresh the page before posting, looks like you got it working anyways

Last edited by Kanegasi : 06-21-20 at 02:40 PM.
  Reply With Quote
06-24-20, 03:15 PM   #7
Aur0r4
A Deviate Faerie Dragon
 
Aur0r4's Avatar
AddOn Compiler - Click to view compilations
Join Date: Feb 2010
Posts: 16
Thanks Kanegesi, it's only half as long, nice. But unfortunately, it gives you an ERROR. :P
__________________
Aur0r4
Yuluria


See Yulu UI in action: here

F.A.Q.
  Reply With Quote
06-24-20, 03:27 PM   #8
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
Thank you for trying my code out, even though you stated you had something working. Unfortunately, "it gives you an ERROR" is not helpful at all.
  Reply With Quote
06-25-20, 09:57 AM   #9
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,308
Both ClassColor() and Angle() are only giving their first return values since they are not at the end of the list. The rest are discarded.

Lua Code:
  1. local s=Status(unit)
  2. if s then return s end
  3. local s1,s2,s3=Angle(AFK(unit) or DND(unit))
  4. local cur,max=HP(unit),MaxHP(unit)
  5. local cr,cg,cb=ClassColor(unit)
  6. local hr,hg,hb=HPColor(cur,max)
  7. return "|cff%02x%02x%02x%s|r %s%s%s || |cff%02x%02x%02x%.0f|r %%",cr,cg,cb,Name(unit),s1,s2,s3,hr,hg,hb,100*cur/max
__________________
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

WoWInterface » Developer Discussions » Lua/XML Help » Combine two lua scripts

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