Developing Addon [Part 1]: The Plan and Attempt Progress with Code | Humbly Request Assistance

Greetings and Salutations!! I THANK you for even viewing and reading my post!!

The Addon that I am trying to develop will, in the end, be able to take upwards of 100,000 Item ID’s and simply display/output the Profession those items belong to in the same order as the list that it belongs with, to another editbox that can be then copied and pasted to a word processor or a txt document with the order maintained. I made a diagram showing what I mean.

So far, what I was able to figure out was how to get the Profession of the Item to print to the default chat console. I believe that is proof that it can be done. Sometimes, for items of mining for example, it will say Metal and Stone. But something like that I can easily manage in a word processor and make it say Mining. A Small issue with the code part I kinda figured out is that here and there it would print a “nil” value. With a reload, it would usually not do that and properly print the attributes of GetItemInfo(). If the nil values still persisted with a reload, I had to logout and log back in on that same character and then it would properly print the attributes.

I also half-managed to get some form of an EditBox so that I can copy from the clipboard to this edit box. It’s not pretty and currently does not work right as I don’t understand how to fix the code.

I also made an attempt, based on how I originally was able to get the Profession Name with the GetItemInfo(), to with the EditBox that I have try and paste into the Edit Box some Item ID’s and have the program recurse through those Item ID’s outputting the Profession Name. But it didn’t work at all….

I also made an attempt to create a Scroll Bar. I’m not sure if it works I think it’s invisible? As when I load the Addon I cannot scroll in the normal chat box until I close the EditBox. Weird huh?

I was looking at wowpedia, as I was being helped, to try and figure out the syntax [maybe not the proper term?] to execute the num = EditBox:GetNumber() function. I am still scratching my head. I bought the 2 books on WoW programming but I was informed to return them to amazon as they are 13 years old and the game has drastically changed so much and that’s why the examples were kinda not working for me really…

At the beginning of my code, which I’ll also put here, I “hardcoded” a value into the variable itemNum just so that I could output the fields from GetItemInfo() to the default chat frame. It definitely shows the Profession of the Item ID, called itemSubType, I just gotta get a lot of em and put it in another edit box that can be copied and pasted to excel or txt document.

So what I was looking for I suppose is resources on how to:

-Properly implement the num=EditBox:GetNumber() function, as the list will be all numbers and I think this function is key

-Make a proper editBox so that I can paste the Item ID numbers into it so that I can create a loop function that will parse this large list

-Make another proper editBox that will display the Profession Name that can be copied to Clipboard

-um…. I can’t think of anything else……

-Enable the buttons to actually do copy and pasting and the conversion when you click on them

This is my first attempt at making an Addon, any help is so very much appreciated!!! :blush:

A Picture Illustrating What I Am Trying To Achieve: um…i have a picture on imgur but it wont let me do it…i dont know why

The Code So Far;

print("PROFESSION LOOK UP")

--Test Item ID Number for printing the Profession Type, it's a Raw Rockscale Cod
local itemNum = 6362


--Display Item Info using GetItemInfo(), showing basic info
local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType,
itemSubType, itemStackCount, itemEquipLoc, itemTexture, itemSellPrice =GetItemInfo(itemNum)




--I know the following is printing to my chatbox only, but i was having a hard time getting the editbox to work so i had to
print (" ")
print ("##Basic Item Info##")
print (" ")
print (itemName)
print (itemLink)
print (itemRarity)
print (itemLevel)
print (itemMinLevel)
print (itemType)
print (itemSubType)                 --this is KEY to printing the Profession type the Item is apart of
print (itemStackCount)
print (itemEquipLoc)
print (itemTexture)
print (itemSellPrice)
print (" ")




--Display Item Info using GetItemInfo(), showing detaied info
local itemName, itemLink, itemQuality, itemLevel, itemMinLevel, itemType, itemSubType,
itemStackCount, itemEquipLoc, itemTexture, sellPrice, classID, subclassID, bindType,
expacID, setID, isCraftingReagent
    = GetItemInfo(itemNum)


print (" ")
print ("##Detailed Item Info##")
print (" ")

	
print (itemName)
print (itemLink)
print (itemRarity)
print (itemLevel)
print (itemMinLevel)
print (itemType)
print (itemSubType)
print (itemStackCount)
print (itemEquipLoc)
print (itemTexture)
print (classID)
print (subclassID)
print (bindType)
print (expacID)
print (setID)
print (isCraftingReagent)
print (" ")

print ("EDIT BOX VALUE?")
print (itemNum)
print (" ")


--Above this line shows proof that I CAN get the Profession name from the Item ID and print it...
--[[################################################################################################################################]]


--Creation of Frame for EditBox??
ProfLookUp = CreateFrame("Frame", nil, UIParent, "BasicFrameTemplateWithInset");

ProfLookUp:SetSize(500, 560);
ProfLookUp:SetPoint("CENTER", UIParent, "CENTER");
ProfLookUp:SetMovable(true);



--Puts the title of the box in the UI so you can actually see it
ProfLookUp.title = ProfLookUp:CreateFontString(nil, "OVERLAY");
ProfLookUp.title:SetFontObject("GameFontHighlight");
ProfLookUp.title:SetPoint("LEFT", ProfLookUp.TitleBg, 5, 0);
ProfLookUp.title:SetText("Profession Look Up")








--scroll bar with up and down button, Does Not Work unfortunately...?
ProfLookUp.ScrollFrame = CreateFrame("ScrollFrame", nil, ProfLookUp, "UIPanelScrollFrameTemplate");
ProfLookUp.ScrollFrame:SetPoint("TOPLEFT", ProfLookUpDialogBG, "TOPLEFT", 4, -8);
ProfLookUp.ScrollFrame:SetPoint("BOTTOMRIGHT", ProfLookUpDialogBG, "BOTTOMRIGHT", -3, 4);

local child = CreateFrame("Frame", nil, ProfLookUp.ScrollFrame);
child:SetSize(308, 500);

ProfLookUp.ScrollFrame:SetScrollChild(child);

ProfLookUp.ScrollFrame.ScrollBar:ClearAllPoints();
ProfLookUp.ScrollFrame.ScrollBar:SetPoint("TOPLEFT", ProfLookUp.ScrollFrame, "TOPRIGHT", -12, -18);
ProfLookUp.ScrollFrame.ScrollBar:SetPoint("BOTTOMRIGHT", ProfLookUp.ScrollFrame, "BOTTOMRIGHT", -7, 18);




--This should be creating my edit box so that i can copy and paste Profession ID's
ProfLookUp.pasteFrame = CreateFrame("EditBox", nil, ProfLookUp, "InputBoxTemplate");
ProfLookUp.pasteFrame:SetPoint("CENTER", ProfLookUp, "CENTER");
ProfLookUp.pasteFrame:SetWidth(400);
ProfLookUp.pasteFrame:SetHeight(400);
ProfLookUp.pasteFrame:SetMovable(true);
ProfLookUp.pasteFrame:SetAutoFocus(false);
ProfLookUp.pasteFrame:SetMultiLine(1000);   --Currently set to accept 1000 rows of 1 Item ID per line?      
ProfLookUp.pasteFrame:SetMaxLetters(1000); --Currently set to accept 1000 characters per line of Item ID's? 
-- For the Edit Box at the end of the day i need it to accept 100,000 Item ID's with one Item ID per line and that item ID being up to 
-- maybe 8 numbers in length or so, prolly 10 max


--This should be creating my button so that i can paste the Item ID's from the Clipboard
ProfLookUp.pasteBtn = CreateFrame("Button", nil, ProfLookUp, "GameMenuButtonTemplate");
ProfLookUp.pasteBtn:SetPoint("CENTER", ProfLookUp, "BOTTOM", 0, 40);
ProfLookUp.pasteBtn:SetSize(120, 30);
ProfLookUp.pasteBtn:SetText("PASTE");
ProfLookUp.pasteBtn:SetNormalFontObject("GameFontNormal");
ProfLookUp.pasteBtn:SetHighlightFontObject("GameFontHighlight");

--[[

--I dont know how to implement getting the number value, which would be the entereed Item ID, from the editbox to print the Profession
--But in the end this needs to traverse a list of Item ID's upwards of 100,000
local num = EditBox:GetNumber()

local itemName, itemLink, itemQuality, itemLevel, itemMinLevel, itemType, itemSubType,
itemStackCount, itemEquipLoc, itemTexture, sellPrice, classID, subclassID, bindType,
expacID, setID, isCraftingReagent
    = GetItemInfo(num)

	print (" ")
	print (" ")
	print (" ")
	print (itemSubType) 
	print (num)
]]





--[[
Use WoW game version number
GetBuildInfo
In particular, /dump select(4, GetBuildInfo()) should output the correct version to your chat frame.

Get Lua Version
/script print(_VERSION)



]]

Thank You For Reaching The End! :blush:

Editbox:GetNumber() will get the first line in the box and if it’s a number will return the number otherwise it returns 0

If you want to grab a list of numbers you will have to use EditBox:GetText() and then parse that using tonumber() (quick/dirty example included)

Doing a /reload, the game will cache certain information so it will be immediatly available when your character enters the world.
Logging out/in clears the cache so it may take some time to aquire certain information ie. if it has to be requested and retruned from the server.

Your code with some very quick/dirty adjustments to get it working if not looking/acting perfectly. Added some comments starting with --[[ Fizz: and a /cpy command to show/hide the frame. Paste/type in a list of numbers (or characters and numbers) and press the button to see what happens.

print("PROFESSION LOOK UP")

--Test Item ID Number for printing the Profession Type, it's a Raw Rockscale Cod
local itemNum = 6362

local backdrop = {
	bgFile = "Interface/BUTTONS/WHITE8X8",
	edgeFile = "",
	tile = true,
	edgeSize = 0,
	tileSize = 0,
	insets = {
		left = 0,
		right = 0,
		top = 0,
		bottom = 0,
	},
}
--[[ Fizz: a function for testing numbers and if they are valid item numbers, add the to a table for posting bnack to the editbox ]]--
local function AddItem(itemtable, itemnum)
	local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, itemTexture, itemSellPrice =GetItemInfo(itemnum)
	if itemName then
		tinsert(itemtable, { itemName=itemName, itemRarity=itemRarity, itemLevel=itemLevel, itemSubType=itemSubType })
	end
end

--Display Item Info using GetItemInfo(), showing basic info
local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType,
itemSubType, itemStackCount, itemEquipLoc, itemTexture, itemSellPrice =GetItemInfo(itemNum)

--I know the following is printing to my chatbox only, but i was having a hard time getting the editbox to work so i had to
print (" ")
print ("##Basic Item Info##")
print (" ")
print (itemName)
print (itemLink)
print (itemRarity)
print (itemLevel)
print (itemMinLevel)
print (itemType)
print (itemSubType)                 --this is KEY to printing the Profession type the Item is apart of
print (itemStackCount)
print (itemEquipLoc)
print (itemTexture)
print (itemSellPrice)
print (" ")

--Display Item Info using GetItemInfo(), showing detaied info
local itemName, itemLink, itemQuality, itemLevel, itemMinLevel, itemType, itemSubType,
itemStackCount, itemEquipLoc, itemTexture, sellPrice, classID, subclassID, bindType,
expacID, setID, isCraftingReagent
    = GetItemInfo(itemNum)

print (" ")
print ("##Detailed Item Info##")
print (" ")
	
print (itemName)
print (itemLink)
print (itemRarity)
print (itemLevel)
print (itemMinLevel)
print (itemType)
print (itemSubType)
print (itemStackCount)
print (itemEquipLoc)
print (itemTexture)
print (classID)
print (subclassID)
print (bindType)
print (expacID)
print (setID)
print (isCraftingReagent)
print (" ")

print ("EDIT BOX VALUE?")
print (itemNum)
print (" ")


--Above this line shows proof that I CAN get the Profession name from the Item ID and print it...
--[[################################################################################################################################]]


--Creation of Frame for EditBox??
--[[ Fizz: make variables local unless you want the seem by every addon a player has loaded 
	That and there's always a chance by not making them local you will fudge up a global variable somonme else really needs.
]]--
--[[ Fizz: Giving a frame a name will add the name to the gloabl table using a refernce to the frame itself. 
	It's also easier to see what frame it is using /fstack (a toggle command) in-game.
]]--
local ProfLookUp = CreateFrame("Frame", "Forthehordes_Addon_Frame", UIParent, "BasicFrameTemplateWithInset");

ProfLookUp:SetSize(500, 560);
ProfLookUp:SetPoint("CENTER", UIParent, "CENTER");
--[[ Fizz: enable dragging ]]--
ProfLookUp:EnableMouse(true)
ProfLookUp:SetMovable(true)
ProfLookUp:SetUserPlaced(true) -- The game will only save poritions of frames created beofre the PLAYER_LOGIN event otherwise saving/resroing is up to youj
ProfLookUp:SetClampedToScreen(false)
ProfLookUp:RegisterForDrag("LeftButton")
ProfLookUp:SetScript("OnDragStart", function(self) 
	self:StartMoving()
end)
ProfLookUp:SetScript("OnDragStop", function(self) 
	self:StopMovingOrSizing()
end)
--[[ end enable dragging ]]--

--Puts the title of the box in the UI so you can actually see it
ProfLookUp.title = ProfLookUp:CreateFontString(nil, "OVERLAY");
ProfLookUp.title:SetFontObject("GameFontHighlight");
ProfLookUp.title:SetPoint("LEFT", ProfLookUp.TitleBg, 5, 0);
ProfLookUp.title:SetText("Profession Look Up")

--scroll bar with up and down button, Does Not Work unfortunately...?
--ProfLookUp.ScrollFrame = CreateFrame("ScrollFrame", nil, ProfLookUp, "UIPanelScrollFrameTemplate");
--ProfLookUp.ScrollFrame:SetPoint("TOPLEFT", ProfLookUpDialogBG, "TOPLEFT", 4, -8);
--ProfLookUp.ScrollFrame:SetPoint("BOTTOMRIGHT", ProfLookUpDialogBG, "BOTTOMRIGHT", -3, 4);

--[[ Fizz: Replaced the sroll/editcox code with code from the example I linked in the original thread ]]--
ProfLookUp.ScrollFrame = CreateFrame("ScrollFrame", "$parentScroll", ProfLookUp, "UIPanelScrollFrameTemplate")
ProfLookUp.ScrollFrame:SetPoint("TOPLEFT", 10, -30)
ProfLookUp.ScrollFrame:SetPoint("BOTTOMRIGHT", -30, 60)
ProfLookUp.pasteFrame = CreateFrame("EditBox", "$parenEditbox", ProfLookUp.ScrollFrame, BackdropTemplateMixin and "BackdropTemplate")
ProfLookUp.pasteFrame:SetBackdrop(backdrop)
ProfLookUp.pasteFrame:SetBackdropColor(0, 0, 0, 1)
ProfLookUp.pasteFrame:SetMultiLine(true)
--ProfLookUp.pasteFrame:SetSize(ProfLookUp.ScrollFrame:GetSize())
ProfLookUp.pasteFrame:SetSize(400, ProfLookUp:GetWidth())
ProfLookUp.pasteFrame:SetPoint("TOPLEFT", ProfLookUp, 10, -30)
ProfLookUp.pasteFrame:SetPoint("BOTTOMRIGHT", ProfLookUp, -30, 60)
--ProfLookUp.pasteFrame:SetPoint("TOPLEFT", ProfLookUp.ScrollFrame)
--ProfLookUp.pasteFrame:SetPoint("BOTTOMRIGHT",ProfLookUp.ScrollFrame, -30, 0)
ProfLookUp.pasteFrame:SetMaxLetters(99999)
ProfLookUp.pasteFrame:SetFontObject(GameFontNormal)
ProfLookUp.pasteFrame:SetAutoFocus(false)
ProfLookUp.pasteFrame:SetScript("OnEscapePressed", function(self) self:ClearFocus() end) 
ProfLookUp.pasteFrame:SetScript("OnEditFocusGained", function(self) if self:GetText() == "Paste Here!" then self:SetText("") end end) 
ProfLookUp.pasteFrame:SetText("Paste Here!")
ProfLookUp.ScrollFrame:SetScrollChild(ProfLookUp.pasteFrame)

--[[ You can cpoy/paste using CTRL-C, X, V but not using a buitton --]]
--This should be creating my button so that i can paste the Item ID's from the Clipboard
ProfLookUp.pasteBtn = CreateFrame("Button", nil, ProfLookUp, "GameMenuButtonTemplate");
ProfLookUp.pasteBtn:SetPoint("CENTER", ProfLookUp, "BOTTOM", 0, 40);
ProfLookUp.pasteBtn:SetSize(120, 30);
--[[ Fizz: It can paster text, just get text that has been paster CTRL-V or typed in ]]--
--ProfLookUp.pasteBtn:SetText("PASTE");
ProfLookUp.pasteBtn:SetText("Is a number?");

ProfLookUp.pasteBtn:SetNormalFontObject("GameFontNormal");
ProfLookUp.pasteBtn:SetHighlightFontObject("GameFontHighlight");
--[[ Fizz: you're OnClick handler tells the button what to do when it's clicked. ]]--
ProfLookUp.pasteBtn:SetScript("OnClick", function(self)
	local Pasted = self:GetParent().pasteFrame:GetText() -- get the text in the edibox as a number
	local StartAt = 1
	local EndAt
	local ItemTable = {}
	local itemNum
	local listItems = ""
	while true do
		EndAt = strfind(Pasted, "\n", StartAt)
		if not EndAt then
			if strlen(Pasted) > StartAt then
				itemNum = tonumber(strsub(Pasted, StartAt, strlen(Pasted)))
			end
			if itemNum then
				AddItem(ItemTable, itemNum)
			end
			break
		end
		itemNum = tonumber(strsub(Pasted, StartAt, EndAt - 1))
		print(itemNum and itemNum or "oops, " .. strsub(Pasted, StartAt, EndAt - 1) .. " is not a number!")
		if itemNum then 
			AddItem(ItemTable, itemNum)
		end
		StartAt = EndAt + 1
	end
	self:GetParent().pasteFrame:SetText("")
	if #ItemTable > 0 then
		local displayString = "itemName=%s, itemRarity=%s, itemLevel=%s\n"
		for k, v in ipairs(ItemTable) do
--			listItems = listItems .. format(displayString, v.itemName, v.itemRarity, v.itemLevel)
			listItems = listItems .. v.itemSubType .. "\n"
		end
		self:GetParent().pasteFrame:SetText(listItems)
	end
end)
1 Like

Oops I left the backdrop around the edit box :stuck_out_tongue_winking_eye:

That and the example I linked in your original thread was broken with the backdrop changes… now fixed I think.

Edit: Update the code in my OP to process the list and if it finds real item numbers, posts them back to the editbox (and remove the backdrop).

1 Like

OH MY!!! THANKS SO MUCH!! It’s like Perfect!! WoW Looking at the code I dont believe i would have figured it out.

Ok so here is also what I did:

ProfLookUp.pasteBtn:SetScript("OnClick", function(self)
	local Pasted = self:GetParent().pasteFrame:GetText() -- get the text in the edibox as a number
	local StartAt = 1
	local EndAt
	local ItemTable = {}
	local itemNum
	while true do
		EndAt = strfind(Pasted, "\n", StartAt)
		if not EndAt then
			if strlen(Pasted) > StartAt then
				itemNum = tonumber(strsub(Pasted, StartAt, strlen(Pasted)))
			end
			if itemNum then
				AddItem(ItemTable, itemNum)
			end
			break
		end
		itemNum = tonumber(strsub(Pasted, StartAt, EndAt - 1))
		print(itemNum and itemNum or "oops, " .. strsub(Pasted, StartAt, EndAt - 1) .. " is not a number!")
		if itemNum then 
			AddItem(ItemTable, itemNum)
		end
		StartAt = EndAt + 1
	end
	self:GetParent().pasteFrame:SetText("")
	local listItems = ""
	if #ItemTable > 0 then
		local displayString = "itemName=%s, itemRarity=%s, itemLevel=%s, itemSubType=%s\n"
		for k, v in ipairs(ItemTable) do
			listItems = listItems .. format(v.itemSubType) --
		end
		self:GetParent().pasteFrame:SetText(listItems)
	end
end

Ok so i was reading and modifying it so that for each item number, it displays only the itemSubType. I added that field to the code.

In the section now, i tested it with a dozen or so item it currently displays like this:

OtherMiscellaneousMountLeatherPotionEnchantingPotionEnchantingEnchantingPotionMiscellaneousFood & DrinkLeatherMiscellaneousMiscellaneousFist WeaponsClothClothKeyEnchantingWeaponWeaponWeaponEnchantingEnchantingEnchantingWeaponFingerWeaponWeaponWeaponWeaponFingerWeaponFingerWeaponWeaponEnchantingFingerFinger

What I am trying to do now is just make it drop down one line each time it prints the Profession the item it belongs to, so instead look like this:

Other
Miscellaneous
Mount
Leather
Potion
Enchanting
Potion
Enchanting
Enchanting
Potion
Miscellaneous
Food & Drink

If we can get it to do that then it’s PERFECTO. i’m trying right now looking it up.

change

listItems = listItems .. format(v.itemSubType)

to

listItems = listItems .. v.itemSubType .. "\n"

Using format() makes it easier to combine multiple variables into a predifined string format but you have to know how it works.
The "\n" creates a new line in the text string and the .. concatinates two strings together.

1 Like

It Worked!!! Yaaaay! I was thinking the \n from the very little c++ programming i knew many moons ago but i couldn’t think how to put it in there.

YOU ARE AWESOME! I truly thank you!

You are welcome and congratulations on what was a very close first effort.

Have fun!

1 Like