View Single Post
03-31-14, 05:01 PM   #36
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
It would be simpler to just ignore the original text and get the name again:
Code:
_G[partyFrame].name:SetText(GetUnitName("party"..i))
If you wanted to show the realm name again in the future, add a second argument true to GetUnitName:
Code:
_G[partyFrame].name:SetText(GetUnitName("party"..i, true))
However, the error you posted indicates that either:

(a) you did not, in fact, make the change Clamsoda suggested, as your originalName variable is still referring to the fontstring, rather than its text contents, or

(b) the unit in question doesn't exist. Using GetUnitName instead of manipulating the existing text will avoid this problem, but you should really not bother doing anything with frames that aren't shown. I see you're checking GetNumGroupMembers() >= 1 on each loop iteration; this is wasteful and won't achieve the desired result anyway, because having 1 party member doesn't mean you have 4 party members. Instead, just check that the frame being processed is shown:

Code:
		for i = 1, MAX_PARTY_MEMBERS do	
			local partyFrame = "PartyMemberFrame"..i
			if partyFrame:IsShown() then
				local originalName = _G[partyFrame].name:GetText()
				local unitName, unitRealm = strsplit("-", originalName)
				_G[partyFrame].name:SetText(unitRealm and unitName.."(*)" or unitName)
			end
However, upon looking at your file, this entire block of code is pointless, because you only run it once when you log in, at which time information about party members may not even be available, and certainly won't update when your group changes. Instead, you should add this code to your UnitFrame_Update hook and remove it from your OnEnable function:

Code:
	hooksecurefunc("UnitFrame_Update", function(self, isParty)
		if not self.name or not self:IsShown() then return end
		
		-- other code here is fine, just omitted from this post for brevity
	 
		self.name:SetTextColor(color.r, color.g, color.b)
		if isParty then
			self.name:SetText(GetUnitName(self.overrideName or unit))
		end
	end)
__________________
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.

Last edited by Phanx : 03-31-14 at 05:11 PM.
  Reply With Quote