Thread Tools Display Modes
09-20-12, 08:23 AM   #1
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Help with Calendar Script!

Hi I'm very new to lua programming and this script below will most likely look very wrong but I want to create a name with text inside which only shows up when there is a calendar event pending and will not show when there is not.

This is it:
Code:
-- Calendar Button
local classcolor = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[(select(2, UnitClass("player")))]	
local cal = CreateFrame("Frame", nil, UIParent)
cal:SetPoint("BOTTOM", Minimap, "BOTTOM")

local calText = cal:CreateFontString(nil, "OVERLAY")
calText:SetPoint("BOTTOM", cal, "BOTTOM", 0, -2)
calText:SetFont("Fonts\\FRIZQT__.ttf", 12, "THINOUTLINE")
calText:SetTextColor(classcolor.r, classcolor.g, classcolor.b)
info:SetText("Calendar")

calText:RegisterEvent("CALENDAR_UPDATE_PENDING_INVITES")
calText:RegisterEvent("CALENDAR_ACTION_PENDING")
calText:SetScript("OnEvent",
	if event == "CALENDAR_UPDATE_PENDING_INVITES" then
		self:Show()
	else
	self:Hide()
	end
	if event == "CALENDAR_ACTION_PENDING" then
	self:Hide()
	end
end)

calText:SetScript("OnClick", function (self, button, down)
if(not CalendarFrame) then LoadAddOn("Blizzard_Calendar") end
Calendar_Toggle()
end)
---------------------
Getting a lot of errors and in the end I gave up.
Also I want the text "Calendar" to show in class color but I will save that until the end as that was just getting in the way and making it more confusing. Thank you.
  Reply With Quote
09-20-12, 04:53 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
1. You are running info:SetText("Calendar") ... but you never defined any object as info.

2. You are trying to register events and set scripts on calText, which is a font string. Font strings don't support events or scripts. You need to do those things with cal, which is a frame, instead.
__________________
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.
  Reply With Quote
09-20-12, 05:53 PM   #3
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Ok, I've researched and asked around abit and created this:
Code:
local classcolor = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[(select(2, UnitClass("player")))]	
local cal = CreateFrame("Frame", nil, UIParent)
local calText = cal:CreateFontString(nil, "OVERLAY")

cal:SetPoint("BOTTOMLEFT",calText,"BOTTOMLEFT",-2, -2)
cal:SetPoint("TOPRIGHT",calText,"TOPRIGHT",2, 2)

calText:SetFont("Fonts\\FRIZQT__.ttf", 12, "THINOUTLINE")
calText:SetTextColor(classcolor.r, classcolor.g, classcolor.b)
calText:SetText("Calendar")
calText:SetPoint("BOTTOM",Minimap,"BOTTOM")

cal:RegisterEvent("CALENDAR_UPDATE_PENDING_INVITES")
cal:RegisterEvent("CALENDAR_ACTION_PENDING")

cal:SetScript("OnEvent", function()
	if CalendarGetNumPendingInvites() > 0 then
		self:Show()
	else
		self:Hide()
	end
end)

cal:SetScript("OnClick", function()
if(not CalendarFrame) then LoadAddOn("Blizzard_Calendar") end
Calendar_Toggle()
end)
but keep getting this error:
<unnamed> doesn't have a "OnClick" script

with this line:
cal:SetScript("OnClick", function()

Is this better? And if so, what is wrong with this line? Cannot figure it out. Thank you.

Also that info text was a typo
  Reply With Quote
09-20-12, 07:23 PM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
If you want to handle clicks, you need an object that handles clicks. A plain frame cannot handle clicks. You need a button, or some derivative of a button. Probably just a button is fine:

Code:
local cal = CreateFrame("Button", nil, UIParent)
On a side note, if you're intending for your button to be attached to the minimap, you should probably parent it to the Minimap, not UIParent.
__________________
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.
  Reply With Quote
09-21-12, 12:38 AM   #5
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Thank you so much! Got it all working now

Last edited by Mayron : 09-21-12 at 01:16 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Help with Calendar Script!


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