Thread Tools Display Modes
04-14-14, 02:55 PM   #1
mightyjay
A Murloc Raider
Join Date: Apr 2014
Posts: 6
SaveVariables

Hello there i found some code tutorials on Savedvariables but something seems wrong as it wont let me press Enter to do the /hwm and it actually never prints me anything

what iam really trying to do is get this part to work correctly so that it could eventually save the infos took from /glogcpy and open them later if asked in a new frame in a editbox and then compare to the new one

but the havewemet part to save variables dosent seems to work
help any one? please

Code:
local frame = CreateFrame("Frame")
frame:RegisterEvent("ADDON_LOADED"); -- Fired when saved variables are loaded
frame:RegisterEvent("PLAYER_LOGOUT"); -- Fired when about to log out

function frame:OnEvent(event, arg1)
 if event == "ADDON_LOADED" and arg1 == "HaveWeMet" then
  -- Our saved variables are ready at this point. If there are none, both variables will set to nil.
  if HaveWeMetCount == nil then
   HaveWeMetCount = 0; -- This is the first time this addon is loaded; initialize the count to 0.
  end
  if HaveWeMetBool then
   print("Hello again, " .. UnitName("player") .. "!");
  else
   HaveWeMetCount = HaveWeMetCount + 1; -- It's a new character.
   print("Hi; what is your name?");
  end
 elseif event == "PLAYER_LOGOUT" then
   HaveWeMetBool = true; -- We've met; commit it to memory.
 end
end
frame:SetScript("OnEvent", frame.OnEvent);
SLASH_HAVEWEMET1 = "/hwm";
function SlashCmdList.HAVEWEMET(msg)
 print("HaveWeMet has met " .. HaveWeMetCount .. " characters.");
end
the other part of the code is this and thats all the addon has for now
Code:
-- Code Pour Garder seulement les Quit dans le GuildLog
local GLogCopyFrame = CreateFrame("Frame", "GLogCopyFrame", UIParent)
tinsert(UISpecialFrames, "GLogCopyFrame")
GLogCopyFrame:SetBackdrop({
	bgFile = [[Interface\DialogFrame\UI-DialogBox-Background]],
	edgeFile = [[Interface\DialogFrame\UI-DialogBox-Border]],
	tile = true, tileSize = 16, edgeSize = 16,
	insets = { left = 3, right = 3, top = 5, bottom = 3 }
})
GLogCopyFrame:SetBackdropColor(0,0,0,1)
GLogCopyFrame:SetWidth(500)
GLogCopyFrame:SetHeight(400)
GLogCopyFrame:SetPoint("CENTER", UIParent, "CENTER")
GLogCopyFrame:Hide()
GLogCopyFrame:SetFrameStrata("DIALOG")
GLogCopyFrame:SetToplevel(true)

local scrollArea = CreateFrame("ScrollFrame", "GLogCopyScroll", GLogCopyFrame, "UIPanelScrollFrameTemplate")
scrollArea:SetPoint("TOPLEFT", GLogCopyFrame, "TOPLEFT", 8, -30)
scrollArea:SetPoint("BOTTOMRIGHT", GLogCopyFrame, "BOTTOMRIGHT", -30, 8)

local editBox = CreateFrame("EditBox", nil, GLogCopyFrame)
editBox:SetMultiLine(true)
editBox:SetMaxLetters(99999)
editBox:EnableMouse(true)
editBox:SetAutoFocus(false)
editBox:SetFontObject(ChatFontNormal)
editBox:SetWidth(400)
editBox:SetHeight(270)
editBox:SetScript("OnEscapePressed", function(self) 
	if self:HasFocus() then 
		self:ClearFocus() 
	else 
		GLogCopyFrame:Hide() 
	end 
end)
GLogCopyFrame.editBox = editBox

scrollArea:SetScrollChild(editBox)

local close = CreateFrame("Button", nil, GLogCopyFrame, "UIPanelCloseButton")
close:SetPoint("TOPRIGHT", GLogCopyFrame, "TOPRIGHT")

local button = CreateFrame("Button")
local Sanitize = function(text)
	button:SetText(text)
	return button:GetText()
end

GLogCopyFrame.On_Show = function(self)
	GLogCopyFrame:RegisterEvent("GUILD_EVENT_LOG_UPDATE")
	QueryGuildEventLog()
end
GLogCopyFrame.On_Hide = function(self)
	GLogCopyFrame.editBox:SetText("")
	GLogCopyFrame:UnregisterEvent("GUILD_EVENT_LOG_UPDATE")
end
GLogCopyFrame.On_Event = function(self,event,...)
	GLogCopyFrame.editBox:SetText("")
	local numEvents = GetNumGuildEvents()
	local evtype, player1, player2, rank, year, month, day, hour
	local msg
	local buffer = ""
	for i = numEvents, 1, -1 do
		evtype, player1, player2, rank, year, month, day, hour = GetGuildEventInfo(i)
		if ( not player1 ) then
			player1 = UNKNOWN
		end
		if ( not player2 ) then
			player2 = UNKNOWN
		end
		if ( evtype == "invite" ) then
			--msg = format(GUILDEVENT_TYPE_INVITE, player1, player2)
      msg=""
		elseif ( evtype == "join" ) then
			--msg = format(GUILDEVENT_TYPE_JOIN, player1)
          msg=""
		elseif ( evtype == "promote" ) then
			--msg = format(GUILDEVENT_TYPE_PROMOTE, player1, player2, rank)
          msg=""
		elseif ( evtype == "demote" ) then
			--msg = format(GUILDEVENT_TYPE_DEMOTE, player1, player2, rank)
          msg=""
		elseif ( evtype == "remove" ) then
			--msg = format(GUILDEVENT_TYPE_REMOVE, player1, player2)
          msg=""
		elseif ( evtype == "quit" ) then
			msg = format(GUILDEVENT_TYPE_QUIT, player1)
      buffer = buffer..msg.."|cff009999   "..format(GUILD_BANK_LOG_TIME, Sanitize(RecentTimeDate(year, month, day, hour))).."|r|n"
		end
		--if ( msg ) then
 			
		--end
	end
	GLogCopyFrame.editBox:SetText(buffer)
end
GLogCopyFrame:SetScript("OnShow",GLogCopyFrame.On_Show)
GLogCopyFrame:SetScript("OnHide",GLogCopyFrame.On_Hide)
GLogCopyFrame:SetScript("OnEvent",GLogCopyFrame.On_Event)

SLASH_GLOGCPY1 = "/glogcpy"
SlashCmdList.GLOGCPY = function()
	GLogCopyFrame:SetShown(not GLogCopyFrame:IsShown())
end

Code:
## Interface: 50400
## Title: Guildloginfo
## SavedVariables: HaveWeMetCount
## SavedVariablesPerCharacter: HaveWeMetBool

Last edited by mightyjay : 04-14-14 at 03:12 PM.
  Reply With Quote
04-14-14, 05:19 PM   #2
TULOA
A Wyrmkin Dreamwalker
 
TULOA's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2009
Posts: 50
Originally Posted by mightyjay View Post
Hello there i found some code tutorials on Savedvariables but something seems wrong as it wont let me press Enter to do the /hwm and it actually never prints me anything

what iam really trying to do is get this part to work correctly so that it could eventually save the infos took from /glogcpy and open them later if asked in a new frame in a editbox and then compare to the new one

but the havewemet part to save variables dosent seems to work
help any one? please

Code:
local frame = CreateFrame("Frame")
frame:RegisterEvent("ADDON_LOADED"); -- Fired when saved variables are loaded
frame:RegisterEvent("PLAYER_LOGOUT"); -- Fired when about to log out

function frame:OnEvent(event, arg1)
 if event == "ADDON_LOADED" and arg1 == "HaveWeMet" then
  -- Our saved variables are ready at this point. If there are none, both variables will set to nil.
  if HaveWeMetCount == nil then
   HaveWeMetCount = 0; -- This is the first time this addon is loaded; initialize the count to 0.
  end
  if HaveWeMetBool then
   print("Hello again, " .. UnitName("player") .. "!");
  else
   HaveWeMetCount = HaveWeMetCount + 1; -- It's a new character.
   print("Hi; what is your name?");
  end
 elseif event == "PLAYER_LOGOUT" then
   HaveWeMetBool = true; -- We've met; commit it to memory.
 end
end
frame:SetScript("OnEvent", frame.OnEvent);
SLASH_HAVEWEMET1 = "/hwm";
function SlashCmdList.HAVEWEMET(msg)
 print("HaveWeMet has met " .. HaveWeMetCount .. " characters.");
end
the other part of the code is this and thats all the addon has for now
Code:
-- Code Pour Garder seulement les Quit dans le GuildLog
local GLogCopyFrame = CreateFrame("Frame", "GLogCopyFrame", UIParent)
tinsert(UISpecialFrames, "GLogCopyFrame")
GLogCopyFrame:SetBackdrop({
	bgFile = [[Interface\DialogFrame\UI-DialogBox-Background]],
	edgeFile = [[Interface\DialogFrame\UI-DialogBox-Border]],
	tile = true, tileSize = 16, edgeSize = 16,
	insets = { left = 3, right = 3, top = 5, bottom = 3 }
})
GLogCopyFrame:SetBackdropColor(0,0,0,1)
GLogCopyFrame:SetWidth(500)
GLogCopyFrame:SetHeight(400)
GLogCopyFrame:SetPoint("CENTER", UIParent, "CENTER")
GLogCopyFrame:Hide()
GLogCopyFrame:SetFrameStrata("DIALOG")
GLogCopyFrame:SetToplevel(true)

local scrollArea = CreateFrame("ScrollFrame", "GLogCopyScroll", GLogCopyFrame, "UIPanelScrollFrameTemplate")
scrollArea:SetPoint("TOPLEFT", GLogCopyFrame, "TOPLEFT", 8, -30)
scrollArea:SetPoint("BOTTOMRIGHT", GLogCopyFrame, "BOTTOMRIGHT", -30, 8)

local editBox = CreateFrame("EditBox", nil, GLogCopyFrame)
editBox:SetMultiLine(true)
editBox:SetMaxLetters(99999)
editBox:EnableMouse(true)
editBox:SetAutoFocus(false)
editBox:SetFontObject(ChatFontNormal)
editBox:SetWidth(400)
editBox:SetHeight(270)
editBox:SetScript("OnEscapePressed", function(self) 
	if self:HasFocus() then 
		self:ClearFocus() 
	else 
		GLogCopyFrame:Hide() 
	end 
end)
GLogCopyFrame.editBox = editBox

scrollArea:SetScrollChild(editBox)

local close = CreateFrame("Button", nil, GLogCopyFrame, "UIPanelCloseButton")
close:SetPoint("TOPRIGHT", GLogCopyFrame, "TOPRIGHT")

local button = CreateFrame("Button")
local Sanitize = function(text)
	button:SetText(text)
	return button:GetText()
end

GLogCopyFrame.On_Show = function(self)
	GLogCopyFrame:RegisterEvent("GUILD_EVENT_LOG_UPDATE")
	QueryGuildEventLog()
end
GLogCopyFrame.On_Hide = function(self)
	GLogCopyFrame.editBox:SetText("")
	GLogCopyFrame:UnregisterEvent("GUILD_EVENT_LOG_UPDATE")
end
GLogCopyFrame.On_Event = function(self,event,...)
	GLogCopyFrame.editBox:SetText("")
	local numEvents = GetNumGuildEvents()
	local evtype, player1, player2, rank, year, month, day, hour
	local msg
	local buffer = ""
	for i = numEvents, 1, -1 do
		evtype, player1, player2, rank, year, month, day, hour = GetGuildEventInfo(i)
		if ( not player1 ) then
			player1 = UNKNOWN
		end
		if ( not player2 ) then
			player2 = UNKNOWN
		end
		if ( evtype == "invite" ) then
			--msg = format(GUILDEVENT_TYPE_INVITE, player1, player2)
      msg=""
		elseif ( evtype == "join" ) then
			--msg = format(GUILDEVENT_TYPE_JOIN, player1)
          msg=""
		elseif ( evtype == "promote" ) then
			--msg = format(GUILDEVENT_TYPE_PROMOTE, player1, player2, rank)
          msg=""
		elseif ( evtype == "demote" ) then
			--msg = format(GUILDEVENT_TYPE_DEMOTE, player1, player2, rank)
          msg=""
		elseif ( evtype == "remove" ) then
			--msg = format(GUILDEVENT_TYPE_REMOVE, player1, player2)
          msg=""
		elseif ( evtype == "quit" ) then
			msg = format(GUILDEVENT_TYPE_QUIT, player1)
      buffer = buffer..msg.."|cff009999   "..format(GUILD_BANK_LOG_TIME, Sanitize(RecentTimeDate(year, month, day, hour))).."|r|n"
		end
		--if ( msg ) then
 			
		--end
	end
	GLogCopyFrame.editBox:SetText(buffer)
end
GLogCopyFrame:SetScript("OnShow",GLogCopyFrame.On_Show)
GLogCopyFrame:SetScript("OnHide",GLogCopyFrame.On_Hide)
GLogCopyFrame:SetScript("OnEvent",GLogCopyFrame.On_Event)

SLASH_GLOGCPY1 = "/glogcpy"
SlashCmdList.GLOGCPY = function()
	GLogCopyFrame:SetShown(not GLogCopyFrame:IsShown())
end

Code:
## Interface: 50400
## Title: Guildloginfo
## SavedVariables: HaveWeMetCount
## SavedVariablesPerCharacter: HaveWeMetBool
Could be wrong but check the case on the frame after its declared. You changed case and i dont think it matters but ya never kno.

And the lack of enter is a misregistration of the slash command. Did it to myself lol.
  Reply With Quote
04-14-14, 05:36 PM   #3
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Is this the complete .toc? You don't load any lua file.
  Reply With Quote
04-16-14, 09:57 AM   #4
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Since you followed the example on wowpedia, I'll point out some things you missed:
  • Your SetScript/OnEvent handler is very, very wrong. Read the example again.
  • Expressly checking against 1/nil or /true/false is thus: if not someVar then ... the only time you need to be more precise is if a variable has three possible returns all giving different results, such as 1/0/nil true/false/nil. Checking against positive returns is simply if someVar then. This will make your code much easier to read, especially in a few months or a year or two down the road.
  • The semicolon at the end of lines is unnecessary, and artificially increases your file size for no reason. Other programming languages use ; but Lua does not. Lua ignores semicolons.
  • And lastly, all your SetScript calls have the same syntax error. They are missing a closing )
  Reply With Quote
04-16-14, 10:10 AM   #5
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
I just noticed this on wowpedia's example, but without loading it into game, I can't confirm. Anyway, isn't there a missing ) at the end of the SetScript function?
Code:
elseif event == "PLAYER_LOGOUT" then
            -- Save the time at which the character logs out
            HaveWeMetLastSeen = time()
    end
end) -- right here, in red?
  Reply With Quote
04-16-14, 10:39 AM   #6
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Originally Posted by myrroddin View Post
  • Your SetScript/OnEvent handler is very, very wrong. Read the example again.
  • And lastly, all your SetScript calls have the same syntax error. They are missing a closing )
Not at all. He's merely declaring the functions separately.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
04-16-14, 07:22 PM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
These all accomplish exactly* the same result:

#1
Code:
frame:SetScript("OnEvent", function(self, event, ...) print(event) end)
#2
Code:
local OnEvent = function(self, event, ...) print(event) end
frame:SetScript("OnEvent", OnEvent)
#3
Code:
local function OnEvent(self, event, ...) print(event) end
frame:SetScript("OnEvent", OnEvent)
#4
Code:
frame.OnEvent = function(self, event, ...) print(event) end
frame:SetScript("OnEvent", frame.OnEvent)
#5
Code:
function frame.OnEvent(self, event, ...) print(event) end
frame:SetScript("OnEvent", frame.OnEvent)
#6
Code:
function frame:OnEvent(event, ...) print(event) end
frame:SetScript("OnEvent", frame.OnEvent)
* Yes, there are minor technical differences in a few cases, but 99.9999999999% of the time they will not be relevant.
__________________
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
04-16-14, 07:29 PM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by mightyjay View Post
... it wont let me press Enter to do the /hwm and it actually never prints me anything
When you can't press Enter in the chat box, that means an error is occuring. You should always, always, always have an error display enabled while working with addon code -- it makes debugging so much simpler when you can see exactly what and where the problem is. Without an error display, your only option is to manually look over every single line of your code trying to spot the mistake, which is obviously a huge waste of time and very difficult.

BugSack is the best choice. If you're really absolutely opposed to installing an addon, you can enable the "Display Lua Errors" in the default Interface Options > Help panel, but the default error display is unable to show you errors that happen during loading, which is when most of the errors happen when writing an addon, making it a lot less useful. It also operates on a "use it or lose it" principle, whereas with BugSack you can dismiss the error popup (or not have it pop up at all) if you're in the middle of something else, and go back and review all the errors later, even after you've logged out or reloaded.
__________________
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

WoWInterface » Developer Discussions » Lua/XML Help » SaveVariables

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