Thread Tools Display Modes
01-25-12, 01:23 PM   #1
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
some string help removing "'" or a '"'

Its been awhile and even looking at my own code i cant remember how to go about removing something from a string. I need to remove the " around the framename string variable so that it can be passed as a function name within the same function. Best way I can see to do this is to use a gsub? and ditch the "" around the framename by doing a local funcname = framename gsub or remove all together the " but i cant remember how that works lol.

This is the code as of right now you can see where im drawing blanks on the framename = part...
Code:
--[[-----------------------------------------------------------------------------
Individual Frames Creation
-------------------------------------------------------------------------------]]
local function DashFrameCreate(frametype, framename, frameparent, template, justify, texture, onenter)
	local frame = CreateFrame(frametype, framename, frameparent, template)
	frame:EnableMouse(true)
	frame:SetHeight(SIZE)
	frame:SetScript('OnLeave', addon.HideTooltip)
	frame.text = frame:CreateFontString(nil, 'OVERLAY', 'GameFontNormalSmall')
	frame.text:SetFont([[Fonts\FRIZQT__.TTF]], 12, 'NORMAL')
	if justify ~= nil then
		frame.text:SetJustifyH(justify)
	end
	if texture == true then
		frame.texture = frame:CreateTexture()
	end
	if frametype == 'Button' then
		frame:RegisterForClicks("AnyUp")
	end
	frame.text:SetPoint('RIGHT')
	frame.text:SetShadowOffset(1, -1)
	local funcname = framename 
	if onenter == true then
		frame:SetScript('OnEnter', funcname..'_OnEnter'(self))
	end
	return frame
end

DashFrameCreate('Frame',"GUI_DashMail", UIParent, nil, 'RIGHT', true, true)
DashFrameCreate('Button',"GUI_DashQuest", UIParent, nil, 'RIGHT', true, true)
DashFrameCreate('Button',"GUI_DashDurability", UIParent, nil, 'RIGHT', true)
DashFrameCreate('Button',"GUI_DashInventory", UIParent, 'SecureHandlerClickTemplate', 'RIGHT', true)
DashFrameCreate('Button',"GUI_DashMoney", UIParent, nil, nil, nil)
DashFrameCreate('Button',"clock", UIParent, nil, 'RIGHT', true)
DashFrameCreate('Frame',"GUI_DashLatency", UIParent, nil, 'RIGHT', nil)
DashFrameCreate('Frame',"GUI_DashFPS", UIParent, nil, 'RIGHT', nil)
DashFrameCreate('Button',"GUI_DashSocial", UIParent, 'SecureHandlerClickTemplate', 'RIGHT', true)
DashFrameCreate('Button', "GUI_DashGuild", UIParent, 'SecureHandlerClickTemplate', 'RIGHT', nil)
DashFrameCreate('Button',"GUI_DashSpeed", UIParent, nil, 'RIGHT', true)
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-25-12, 02:22 PM   #2
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
NM that was a bad idea in the first place i think... lol. going a whole different route...
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-25-12, 09:05 PM   #3
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
You can't get local variable names through string concatenation (or formatting, or whatever).

A better solution would be to use tables to define the frames you want to create, and their attributes:
Lua Code:
  1. -- First, define a set of default properties for reference.
  2. -- See #1 in the Notes list below.
  3. local frameDefaults = {
  4.     object = "Frame", -- string
  5.     parent = UIParent, -- nil or object
  6.     template = nil, -- nil or string
  7.     justify = "RIGHT", -- string; LEFT, RIGHT, or CENTER
  8.     texture = nil, -- boolean
  9.     funcOnEnter = nil, -- function
  10. }
  11. -- Now list the actual frames you want to create, as well as any
  12. -- properties that differ from the default ones:
  13. local frames = {
  14.     ["GUI_DashMail"] = {
  15.         texture = true,
  16.         onEnter = function(self)
  17.             print("Mouse entered GUI_DashMail frame!")
  18.         end
  19.     },
  20.     ["GUI_DashGuild"] = {
  21.         object = "Button",
  22.         template = "SecureHandlerClickTemplate",
  23.     }
  24. }

Then just loop through the table and create all of the frames defined:

Lua Code:
  1. local function DashCreateFrame(name, data)
  2.     local frame = CreateFrame(
  3.         data.object or "Frame",  -- default to "Frame" if not defined
  4.         name,                    -- required
  5.         data.parent or UIParent, -- default to UIParent
  6.         data.template            -- optional
  7.     )
  8.     frame:EnableMouse(true)
  9.     frame:SetHeight(SIZE)
  10.     frame:SetScript("OnLeave", addon.HideTooltip)
  11.  
  12.     frame.text = frame:CreateFontString(nil, "OVERLAY") -- See #2
  13.     frame.text:SetPoint("RIGHT")
  14.     frame.text:SetFont([[Fonts\FRIZQT__.TTF]], 12) -- See #3
  15.     frame.text:SetShadowOffset(1, -1)
  16.     frame.text:SetJustifyH(data.justify or "RIGHT")
  17.  
  18.     if data.object == "Button" then
  19.         frame:RegisterForClicks("AnyUp")
  20.     end
  21.  
  22.     if data.texture then
  23.         frame.texture = frame:CreateTexture()
  24.     end
  25.  
  26.     frame:SetScript("OnEnter", data.funcOnEnter) -- See #4
  27.  
  28.     return frame
  29. end
  30.  
  31. for name, data in pairs(framesToCreate) do
  32.     DashCreateFrame(name, data)
  33. end

This method will make it easier to add new frames and properites in the future, as well as making your code easier to read and understand now, since you don't have to remember which argument means what when they are all stored in descriptive key/value pairs.

Notes:
  1. Strictly speaking, the x=nil defaults aren't necessary, and don't do anything since the key is removed immediately upon setting its value to nil, but it may be helpful to see them listed anyway so you can see all the possible properties in one place.
  2. Since you immediately call SetFont to change the font file, size, and flags, there's no point in inheriting from a font template.
  3. "NORMAL" is not a valid parameter to SetFont. See http://wowprogramming.com/docs/widge...stance/SetFont for details.
  4. Passing a nil value to SetScript is fine, so you don't need to check if data.funcOnEnter exists first.
  Reply With Quote
01-29-12, 03:18 PM   #4
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
Code:
for name, data in pairs(framesToCreate) do
    DashCreateFrame(name, data)
end
where it says frames to create that would really be frames according to your above code? or where does it get that from? and i had tried to table the functions once before but because of the secure attribute function for the backpack stuff it has a problem. Im thinking of using this though for everything else and leaving the onenters and other event functions out of it still. Maybe in doing so it will alleviate the disconnecting issue...
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-29-12, 05:27 PM   #5
Xubera
A Cobalt Mageweaver
 
Xubera's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 207
Originally Posted by Grimsin View Post
Code:
for name, data in pairs(framesToCreate) do
    DashCreateFrame(name, data)
end
where it says frames to create that would really be frames according to your above code? or where does it get that from? and i had tried to table the functions once before but because of the secure attribute function for the backpack stuff it has a problem. Im thinking of using this though for everything else and leaving the onenters and other event functions out of it still. Maybe in doing so it will alleviate the disconnecting issue...

framesToCreate is a table defining your table definitions. According to his first example. the table "frames" (Lines 13 to 24 in the first code box) would be the table you would put in for "framesToCreate" Think of the table as defining a list of features per table, and the function DashCreateFrame looking at each option from the table you define and applying those settings.
__________________
Chat Consolidate is the solution to any out of control trade chat. Ignore lines, throttle chat, consolidate posts!Follow the link to find out how!

▲ ▲ WoWInterface wont let me triforce >.>
  Reply With Quote
01-30-12, 04:44 AM   #6
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
can other things be added to the table? like the set points? example
Code:
["GUI_DashSpeed"] = {
		texture = true,
		textureheight = 10,
		texturewidth = 10,
		textureanchor = "LEFT", frame, "LEFT", 0, 0,
	},
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-30-12, 08:55 AM   #7
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
Originally Posted by Grimsin View Post
can other things be added to the table? like the set points? example
Code:
["GUI_DashSpeed"] = {
		texture = true,
		textureheight = 10,
		texturewidth = 10,
		textureanchor = "LEFT", frame, "LEFT", 0, 0,
	},
Sure, though more like this:

Code:
["GUI_DashSpeed"] = {
		texture = true,
		textureheight = 10,
		texturewidth = 10,
		textureanchor = "LEFT", frame, "LEFT", 0, 0,
		point = "LEFT",
		relative_to = frame,
		relative_point = "LEFT",
		offset_x = 0,
		offset_y = 0,
},
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote
01-30-12, 12:08 PM   #8
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
Hmm but then how does that go into the function? do i need to put each variable into the setpoint? Also the default is purely for reference right? in order to make the actual function default to that i have to use the "or"?

This is where ive gone with it so far and no luck yet with stopping the disconnects..
Code:
-- First, define a set of default properties for reference.
local frameDefaults = {
	object = "Frame", -- string
	parent = DashBoardFrame, -- nil or object
	template = nil, -- nil or string
	justify = "RIGHT", -- string; LEFT, RIGHT, or CENTER
	text = "188",
	framewidth = nil,
	texture = nil, -- boolean
	texturepath = nil,
	textureheight = 12,
	texturewidth = 12,
}
-- Now list the actual frames you want to create, as well as any
-- properties that differ from the default ones:
local dashFramesToCreate = {
	["GUI_DashMail"] = {
		texture = true,
		texturepath = [[Interface\AddOns\]] .. addonName .. [[\Media\MailIcon]],
	},
	["GUI_DashQuest"] = {
		object = "Button",
		text = " 25/25",
		texture = true,
		texturepath = [[Interface\AddOns\]] .. addonName .. [[\Media\QuestIcon]],
	},
	["GUI_DashDurability"] = {
		object = "Button",
		text = "  100%",
		texture = true,
		texturepath = [[Interface\Icons\Trade_BlackSmithing]],
	},
	["GUI_DashInventory"] = {
		object = "Button",
		texture = true,
		template = "SecureHandlerClickTemplate",
		text = " 888/888",
		textureheight = SIZE,
		texturewidth = SIZE,
		texturepath = [[Interface\AddOns\]] .. addonName .. [[\Media\BagIcon]],
	},
	["GUI_DashMoney"] = {
		framewidth = 1,
		object = "Button",
		justify = nil,
		text = nil
	},
	["GUI_DashSocial"] = {
		object = "Button",
		template = "SecureHandlerClickTemplate",
		texture = true,
		textureheight = 20,
		texturewidth = 20,
		texturepath = "Interface/FriendsFrame/UI-Toast-FriendOnlineIcon.blp",
	},
	["GUI_DashGuild"] = {
		object = "Button",
		template = "SecureHandlerClickTemplate",
		texture = true,
		textureheight = 26,
		texturewidth = 21,
		texturepath = "Interface/Buttons/UI-MicroButton-Guild-Banner.blp",
	},
	["GUI_DashClock"] = {
		object = "Button",
		texture = true,
		text = " 18:88pm",
		textureheight = SIZE,
		texturewidth = nil,
		texturepath = "Interface/PlayerFrame/UI-PlayerFrame-Deathknight-Glow.blp",
	},
	["GUI_DashLatency"] = {
		text = " 888ms",
	},
	["GUI_DashFPS"] = {
		text = " 188fps",
	},
	["GUI_DashSpeed"] = {
		framewidth = 46,
		texture = true,
		text = " 100%",
		textureheight = 10,
		texturewidth = 10,
		texturepath = "Interface/TAXIFRAME/UI-Taxi-Icon-Green.blp",
	},
}

local function DashCreateFrame(name, data)
	local frame = CreateFrame(
		data.object or "Frame",  -- default to "Frame" if not defined
		name,                    -- required
		data.parent or DashBoardFrame, -- default to UIParent
		data.template            -- optional
	)
	frame:EnableMouse(true)
	frame:SetHeight(SIZE)
	frame:SetScript("OnLeave", addon.HideTooltip)
	frame:SetFrameStrata("HIGH")
	if data.framewidth then
		frame:SetWidth(data.framewidth)
	end
	frame.text = frame:CreateFontString(nil, "OVERLAY")
	frame.text:SetPoint("RIGHT")
	frame.text:SetFont([[Fonts\FRIZQT__.TTF]], 12)
	frame.text:SetShadowOffset(1, -1)
	frame.text:SetJustifyH(data.justify or "RIGHT")
	frame.text:SetText(data.text or "188")
	
	if data.object == "Button" then
		frame:RegisterForClicks("AnyUp")
	end
	
	if data.texture then
		frame.texture = frame:CreateTexture()
		frame.texture:SetTexture(data.texturepath)
		frame.texture:SetHeight(data.textureheight or 12)
		frame.texture:SetWidth(data.texturewidth or 12)
		if data.textureanchor then
			frame.texture:SetPoint('RIGHT', frame.text, 'LEFT')
		end
	end
	
	return frame
end

for name, data in pairs(dashFramesToCreate) do
	DashCreateFrame(name, data)
end

-- Mail frame --
GUI_DashMail:SetWidth(GUI_DashMail.text:GetStringWidth() + GUI_DashMail.texture:GetWidth() - 8)
GUI_DashMail.texture:SetPoint('RIGHT', GUI_DashMail.text, 'LEFT')
-- Quests --
GUI_DashQuest.texture:SetTexCoord(0.25, 0.75, 0.25, 0.75)
GUI_DashQuest:SetWidth(GUI_DashQuest.text:GetStringWidth() + GUI_DashQuest.texture:GetWidth())
GUI_DashQuest.texture:SetPoint('RIGHT', GUI_DashQuest.text, 'LEFT')
-- Armor durability --
GUI_DashDurability.texture:SetTexCoord(0.07, 0.93, 0.07, 0.93)
GUI_DashDurability:SetWidth(GUI_DashDurability.text:GetStringWidth() + GUI_DashDurability.texture:GetWidth())
GUI_DashDurability.texture:SetPoint('RIGHT', GUI_DashDurability.text, 'LEFT')
-- Inventory --
addon.GUI_DashInventory = GUI_DashInventory -- Needs to be made global for secure attrib functions in other files
GUI_DashInventory:SetWidth(GUI_DashInventory.text:GetStringWidth() + GUI_DashInventory.texture:GetWidth())
GUI_DashInventory.texture:SetPoint('RIGHT', GUI_DashInventory.text, 'LEFT')
-- Clock --
GUI_DashClock:SetWidth(GUI_DashClock.text:GetStringWidth())
GUI_DashClock.texture:SetWidth((GUI_DashClock.text:GetStringWidth() - 6))
GUI_DashClock.texture:SetPoint("CENTER", GUI_DashClock, "CENTER", 5, 0)
GUI_DashClock.texture:Hide()
-- Latency --
GUI_DashLatency:SetWidth(GUI_DashLatency.text:GetStringWidth())
-- FPS --
GUI_DashFPS:SetWidth(GUI_DashFPS.text:GetStringWidth())
-- Social/Friends --
GUI_DashSocial:SetWidth(GUI_DashSocial.text:GetStringWidth() + GUI_DashSocial.texture:GetWidth() - 10)
GUI_DashSocial.texture:SetPoint('RIGHT', GUI_DashSocial.text, 'LEFT')
-- Guild Frame --
GuildMicroButtonTabard:SetParent(GUI_DashGuild)
GuildMicroButtonTabard:SetPoint('RIGHT', GUI_DashGuild.text, 'LEFT')
GuildMicroButtonTabard:SetHeight(5)
GuildMicroButtonTabard:SetWidth(5)
GuildMicroButtonTabard.emblem:SetHeight(9)
GuildMicroButtonTabard.emblem:SetWidth(9)
GuildMicroButtonTabard.background:SetHeight(26)
GuildMicroButtonTabard.background:SetWidth(21)
GuildMicroButtonTabard.emblem:SetPoint("CENTER", GuildMicroButtonTabard.background, "CENTER", 0, -4)
GUI_DashGuild.texture:SetPoint('RIGHT', GUI_DashGuild.text, 'LEFT', 0, 4)
GUI_DashGuild.texture2 = GUI_DashGuild:CreateTexture()
GUI_DashGuild.texture2:SetTexture("Interface/GUI_DashGuild/GuildEmblems_01.blp")
GUI_DashGuild.texture2:SetPoint('CENTER', GUI_DashGuild.texture1, 'CENTER', 0, -4)
GUI_DashGuild.texture2:SetHeight(9)
GUI_DashGuild.texture2:SetWidth(9)
GUI_DashGuild:SetWidth(GUI_DashGuild.text:GetStringWidth() + GUI_DashGuild.texture:GetWidth() - 10)
-- Speed --
GUI_DashSpeed.texture:SetPoint('LEFT', GUI_DashSpeed, 'LEFT')
GUI_DashSpeed.texture:SetTexCoord(0.25, 0.75, 0.25, 0.75)
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]

Last edited by Grimsin : 01-30-12 at 01:28 PM.
  Reply With Quote
01-30-12, 01:27 PM   #9
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
Precisely.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » some string help removing "'" or a '"'

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