04-14-14, 02:55 PM | #1 |
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 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. |
|
04-14-14, 05:19 PM | #2 | |
And the lack of enter is a misregistration of the slash command. Did it to myself lol. |
||
04-14-14, 05:36 PM | #3 |
Is this the complete .toc? You don't load any lua file.
|
|
04-16-14, 09:57 AM | #4 |
Since you followed the example on wowpedia, I'll point out some things you missed:
|
|
04-16-14, 10:10 AM | #5 |
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? |
|
04-16-14, 10:39 AM | #6 |
Not at all. He's merely declaring the functions separately.
__________________
Grab your sword and fight the Horde! |
|
04-16-14, 07:22 PM | #7 |
These all accomplish exactly* the same result:
#1 Code:
frame:SetScript("OnEvent", function(self, event, ...) print(event) end) Code:
local OnEvent = function(self, event, ...) print(event) end frame:SetScript("OnEvent", OnEvent) Code:
local function OnEvent(self, event, ...) print(event) end frame:SetScript("OnEvent", OnEvent) Code:
frame.OnEvent = function(self, event, ...) print(event) end frame:SetScript("OnEvent", frame.OnEvent) Code:
function frame.OnEvent(self, event, ...) print(event) end frame:SetScript("OnEvent", frame.OnEvent) Code:
function frame:OnEvent(event, ...) print(event) end frame:SetScript("OnEvent", frame.OnEvent)
__________________
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. |
|
04-16-14, 07:29 PM | #8 | |
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. |
||
WoWInterface » Developer Discussions » Lua/XML Help » SaveVariables |
«
Previous Thread
|
Next Thread
»
|
Thread Tools | |
Display Modes | |
|
|