Awesome guide.
Rilanciownz-Outland Eu
Desertwolf-Sylvanas Eu
nice guide, maybe you should add something about basics of oop
Last edited by Mroz123; 2011-01-03 at 10:29 PM.
The first guide i've found useful
really awesome guide m8! really intrested on learning some lua coding ;]
Oh god.. so many bad programming memories!
But a great guide none the less
I'll use it when the nightmares go away :P
Alrighty. Updated the guide a few hours ago thanks to some suggestions and errors I had in the original. Thanks for the help!
Little typo (or is it intended?) I noticed. In the example where you cite me, you're not definiting it as a method, merely putting the function as another value into the table. You might want to explain that defining it as a method allows usage of "self".
I'm trying to get this old addon to work , its quite simple i guess, but I have no clue why it is not loading at all.
function SellSound_OnEvent()
if ( event == "ADDON_LOADED" and arg1 == "SellSound") then
DEFAULT_CHAT_FRAME:AddMessage("SellSound 2.4 loaded!");
end
if event == "CHAT_MSG_SYSTEM" and strfind(arg1,"A buyer has been found") then
PlaySoundFile("Interface\\Addons\\SellSound\\cashregister.mp3");
end
end
local frame = CreateFrame("Frame");
frame:SetScript("OnEvent", SellSound_OnEvent);
frame:RegisterEvent("CHAT_MSG_SYSTEM");
frame:RegisterEvent("ADDON_LOADED");
and the toc :
## Interface: 40000
## Title: SellSound
## Notes: Simple addon that plays a cash register sound when you sell something at auction.
## Author:
## Version: 4.0
## LoadOnDemand: 0
## DefaultState: Enabled
sellsound.lua
edit: somehow when i copy paste it here , cashregister has a space in it , but this is not the case in my lua file
I believe there is a logical error in the example code.
Perhaps it should read:Code:for name,number in pairs(mySavedVar) do if UnitName("Player") == name then mySavedVar[name] = mySavedVar[name] + 1 else mySavedVar[UnitName("Player")] = 1 end end
Code:local found = 0 for name,number in pairs(mySavedVar) do if UnitName("Player") == name then mySavedVar[name] = mySavedVar[name] + 1 found = 1 end end if found == 0 then mySavedVar[UnitName("Player")] = 1 end
If you want to do little modification, replace line 1 with this:
If you want to optimize the whole thing, replace the Lua file with:Code:function SellSound_OnEvent(self, event, arg1)
EDIT: Oh yeah, use [code] tags.Code:local frame:CreateFrame("Frame") frame:SetScript("OnEvent", function(self, event, a1) if event == "ADDON_LOADED" and a1 == "SellSound" then print("SellSound 2.4 loaded!") self:UnregisterEvent("ADDON_LOADED") return end if event == "CHAT_MSG_SYSTEM" and a1:find("A buyer has been found") then PlaySoundFile("Interface\\AddOns\\SellSound\\cashregister.mp3") end end) frame:RegisterEvent("CHAT_MSG_SYSTEM") frame:RegisterEvent("ADDON_LOADED")
thank you so much for helping with this , also makes me understand it better.....<3
Thanks again for the catch
---------- Post added 2011-01-04 at 05:14 PM ----------
There isn't a problem with the logic I believe. The way I did it the first time checks to see if the name of the current character is already stored in the mySavedVar variable, and if it isn't adds it to the table.
Yours does the same thing, but is a little bit more long-winded. Unless maybe I'm just not understanding what you mean by a error in the logic.
Care to elaborate?
Let's take a scenario where the table contains the following data and the player logs in with Brusalk character.
The first iteration of the loop would set mySavedVar["Brusalk"] to 11 and the next iteration sets it to 1. Resulting data:Code:mySavedVar["Brusalk"] = 10 mySavedVar["Thiran"] = 10
Code:mySavedVar["Brusalk"] = 1 mySavedVar["Thiran"] = 10
Still useless. pairs() should only be used to check for values, not check for keys.
Interject! Your logic works properly for only one character (one 'name' index in 'mySavedVar'). If mySavedVar has more than one character index (you login with a different character), the iterator will wind up traversing 'name' values that don't match UnitName("Player"), which will trip the 'else' case and reset mySavedVar[UnitName("Player")] to 1.
I guess you could write it as following. It would not fit the guide because no beginner would understand it and it would not demostrate how to use the for loop.
Code:local c = UnitName("player") mySavedVar[c] = (mySavedVar[c] or 0) + 1