Thread Tools Display Modes
07-06-10, 03:32 PM   #1
morkesh
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jun 2010
Posts: 15
Another dynamic creation issue :(

Code:
	colorswatchname = "optionColorSwatch"..NumOptions
	optioncolorswatchname = "optioncolorswatchname"..NumOptions
	
	optionColorSwatchButton = CreateFrame("Button", "optionColorSwatchButton"..NumOptions, CategoryFrame)
	optionColorSwatchButton:SetWidth(22)
	optionColorSwatchButton:SetHeight(22)
	optionColorSwatchButton:SetPoint("TOPLEFT", 500, distanceTop + 2)
	optionColorSwatchButton:SetNormalTexture("Interface\\ChatFrame\\ChatFrameColorSwatch")

	optionColorSwatchTexture = optionColorSwatchButton:CreateTexture("optionColorSwatch"..NumOptions, "OVERLAY")
	optionColorSwatchTexture:SetWidth(12)
	optionColorSwatchTexture:SetHeight(12)
	optionColorSwatchTexture:SetPoint("CENTER", optionColorSwatchButton, 0, 0)
	optionColorSwatchTexture:SetTexture(HexToRGBPerc(ErrDB.ErrColor[i]))

	optionColorSwatchButton:SetScript("OnClick", function(self)
		ShowColorPicker(ErrDB.ErrColor[i], nil, self:GetName())
	end)
		
end

CreateCategoryFrame("General Errors", 100, 0)
CreateOption(CategoryFrame1, 2, -16)
CreateOption(CategoryFrame1, 15, -44)
CreateOption(CategoryFrame1, 17, -72)
CreateCategoryFrame("General Errors", 100, -120)

function ShowColorPicker(hex, CPa, which)
	local rhex, ghex, bhex = string.sub(hex, 1, 2), string.sub(hex, 3, 4), string.sub(hex, 5, 6)

	print(which)

	ColorPickerFrame:SetColorRGB(tonumber(rhex, 16)/255,tonumber(ghex, 16)/255,tonumber(bhex, 16)/255);
	ColorPickerFrame.hasOpacity, ColorPickerFrame.opacity = (CPa ~= nil), CPa;
	ColorPickerFrame.previousValues = {tonumber(rhex, 16)/255,tonumber(ghex, 16)/255,tonumber(bhex, 16)/255,CPa};
	ColorPickerFrame.func =
		function()
			name = string.gsub(which, "Button", "")
			print(name)
			name:SetTexture(ColorPickerFrame:GetColorRGB())
		end
 	ColorPickerFrame:Hide(); -- Need to run the OnShow handler.
	ColorPickerFrame:Show();
end
Bad code is probably ****ty, but why isen't this working? i get the following error

Code:
attempt to call method 'SetTexture' (a nil value)
so i reckon it's the name:SetTexture that's wrong, but how would i do this in an effective manner?
  Reply With Quote
07-06-10, 04:09 PM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,929
I think, not 100% though, that the following lines are what you are getting mixed up with :

optionColorSwatchButton = CreateFrame("Button", "optionColorSwatchButton"..NumOptions, CategoryFrame)
optionColorSwatchTexture = optionColorSwatchButton:CreateTexture("optionColorSwatch"..NumOptions, "OVERLAY")

The last line I believe should be something like :

optionColorSwatchTexture = optionColorSwatchButton:CreateTexture("optionColorSwatch"..NumOptions.."Texture", "OVERLAY")


Edit: Scratch that. Read through a third time and saw what you did

You don't need to use "optionColorSwatch"..NumOptions again as the name as you created a variable for it. although by the looks of it a global variable ( hopefully just for testing purposes ).

Also, you didn't point out what print(name) displayed. did that print as nil or a value that reflects the name you gave the frame in question ? Are you sure its the name:CreateTexture or is it the earlier CreateTexture ? Did the line number match ?
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818

Last edited by Xrystal : 07-06-10 at 04:13 PM.
  Reply With Quote
07-06-10, 04:20 PM   #3
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
I think you want:
Code:
name:SetTexture(ColorPickerFrame:GetColorRGB())
to be:
Code:
_G[name]:SetTexture(ColorPickerFrame:GetColorRGB())
  Reply With Quote
07-06-10, 04:24 PM   #4
morkesh
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jun 2010
Posts: 15
So simple? will test it tommorow! but european realms are down for 24 hours now so meh :/ thanks for pointing out that it was a global variable, it's my 3rd addon and therefore i'm not really that much into it yet :/ i reckon i want "local" before all my variables?

but print(name) printed "optionColorSwatch1" so in that sense it should be working, might be the lack of _G[] though, i guess it checks globally yeah? also before adding name:SetTexture, everything was working fine, texture got set right first time around

Last edited by morkesh : 07-06-10 at 04:32 PM.
  Reply With Quote
07-06-10, 04:31 PM   #5
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,929
Yeah, _G[name] would turn it into an object. I did read around that you didn't have to do that but I always do it just to be safe.

And yeah, also put a local in front of any variables you want to control inside your file. Remember local makes the variable local to the block it is in.

Code:
local fileLocal

local function AFunction()
   local funcLocal
   if aValue == bValue then
      local ifLocal
   else
     local elseLocal
   end
end

local fileLocalFromThisPointForward
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
07-06-10, 04:38 PM   #6
morkesh
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jun 2010
Posts: 15
Arh alright, thanks for the help, much appreciated! In general right now, i'd love to read up on optimization since i feel alot of the things i do, are done in a horrible way because of lack of said knowledge, so any links etc. would be appreciated, currently in my addon i have a function to create a category in my options (created a blank frame with a texture) and a function to create an option in said frame (creates a checkbox, a dropdownmenu and the blasted colorchanger that's been bothering me all day) seems like a bad way to me, but couldn't come up with a better approach
  Reply With Quote
07-06-10, 04:53 PM   #7
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,929
Yeah, it took me a while to play with interface options. I only use the built in interface setup though for settings that wouldn't be changed on the fly as I found out the hard way that you can't do squat with that window open like moving the frame you want to change the size or position of but can't get access so you either cancel all the changes you made to start over after you moved the frame or you accept the changes and hope theyre okay rofl.

As to color swatches. I haven't touched those quite yet. I'm currently learning how to make drop down menus without the need for Ace. So far I can make a single menu with a few options but one of my addons has a hefty menu system using Ace that I would like to break down if I can but will have to wait until I have figured it out.

For code help I usually jump between wowprogramming.com and wowwiki.com. They usually have all the information you might need between them. Then of course looking at the blizz code itself for how the functions work together and then looking at someones addon that does something similar and tweak it
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
07-06-10, 05:17 PM   #8
morkesh
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jun 2010
Posts: 15
haha sounds much like my approach! i have played around with dropdown in my first ever addon, ended up turning useless since the need for a minimap icon wasen't really present, i've personally decided not to touch ACE before i have the basics in place, feels like cheating to me for now atleast ;P as for colorswatches, don't :P took me way longer than i had thought it would, reverse engineering blizzards ChatConfigCheckBoxWithSwatchTemplate

Last edited by morkesh : 07-06-10 at 05:19 PM.
  Reply With Quote
07-06-10, 05:21 PM   #9
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,929
rofl. Yeah, I'm trying to avoid it for the moment. But people do like flexibility with their addons so at some point something other than my chosen design should be available
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
07-06-10, 05:51 PM   #10
morkesh
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jun 2010
Posts: 15
they sure do :P same reason i had to read up on MSBT, SCT & Parrot to make sure my addon could pass data to them, even though i never use said addons.

But oh well, the customer is always right i guess? :P
  Reply With Quote
07-06-10, 06:02 PM   #11
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,929
Nope, the customer is not always right. But they are King So whether we think they are right or not we need to try and set things up for flexibility. But of course, if the addon is initially there for your use then the flexibility is at the pace you want to adjust it with
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
07-06-10, 06:38 PM   #12
morkesh
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jun 2010
Posts: 15
hehe true that, in the case with this addon, it became popular alot faster than i had anticipated and therefore i feel i need to keep up with demands :P

so to quote the peons of warcraft3; Work work!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Another dynamic creation 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