After reading this I immediatly wanted to try and make some addons of my own. I have some experience as a PHP programmer so I figured that I might be able to learn lua pretty quickly. But I've run into some problems I can't seem to get fixed.
The addon I'm trying to make is something like titanpanel. A frame at the top of my screen that is styled by the main addon and then make some little addons that put text on that bar. So I started of with the first part, a bar at the top of my screen. I made the following code for that:
Code:
-- Frames
local EventFrame = CreateFrame("Frame")
local Topbar = CreateFrame("Frame", "jbTopbar", UIParent)
-- Variables
local ResolutionWidth = GetScreenWidth()
local BackgroundTexture = "Interface\\Addons\\jbTopbar\\Textures\\jbBackground.tga"
local BorderTexture = "Interface\\Addons\\jbTopbar\\Textures\\jbBorder.tga"
-- Fonts
jbFont = CreateFont("jbFont")
jbFont:SetFont("Interface\\Addons\\jbTopbar\\Fonts\\jbFont.ttf",10)
jbFont:SetTextColor(1,1,1,1)
-- Events
EventFrame:RegisterEvent("PLAYER_LOGIN")
-- OnEvent
EventFrame:SetScript("OnEvent", function(self,event,...)
Topbar:SetFrameStrata("BACKGROUND")
Topbar:SetWidth(ResolutionWidth)
Topbar:SetHeight(100)
Topbar:SetPoint("TOPLEFT", 0, 0)
Topbar:SetBackdrop({
bgFile = BackgroundTexture,
edgeFile = BorderTexture,
tile = true,
tileSize = 16,
edgeSize = 16,
insets = {
left = 0, right = 0, top = 0, bottom = 4
}
})
Topbar:SetBackdropColor(0,0,0,1)
Topbar:SetBackdropBorderColor(0,0,0,1)
end)
Now this gives no errors but it doesn't display a frame either. The font I created is intentionally global so I can use it in the little addons that I'm making to implement in this one. The next one is a little one that is intented to show the players money:
Code:
-- Frames
local EventFrame = CreateFrame("Frame")
local TopbarMoney = CreateFrame("Frame", "jbTopbarMoney", jbTopbar)
-- Fontstrings
local TopbarMoneyText = TopbarMoney:CreateFontString("TopbarMoneyText")
TopbarMoneyText:SetFontObject(jbFont)
-- Variables
local PlayerMoney
local PlayerGold
local PlayerSilver
local PlayerCopper
local MoneyString
-- Events
EventFrame:RegisterEvent("PLAYER_LOGIN")
EventFrame:RegisterEvent("PLAYER_MONEY")
-- OnEvent
EventFrame:SetScript("OnEvent", function(self,event,...)
PlayerMoney = GetMoney()
PlayerGold = floor(abs(PlayerMoney / 10000))
PlayerSilver = floor(abs(mod(PlayerMoney / 100, 100)))
PlayerCopper = floor(abs(mod(PlayerMoney, 100)))
MoneyString = PlayerGold.."G "..PlayerSilver.."S "..PlayerCopper
TopbarMoneyText:SetText(MoneyString)
end)
This one does give an error, bugsack reports this:
Code:
1x jbTopbarMoney\jbTopbarMoney.lua:31: TopbarMoneyText:SetText(): Font not set
jbTopbarMoney\jbTopbarMoney.lua:31: in function <jbTopbarMoney\jbTopbarMoney.lua:25>
I am currious why it tells me there is no font set while I set it in the main addon file. Or do I still have to include that file into this one? I was thinking that I wouldn't have to because the font is global. So can anyone give me some pointers on what I'm doing wrong?
Thanks in advance!