Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
WoW
Talk
English
Views
Read
Edit
History
More
Search
Navigation
Home
Random page
Help using wiki
Editions
for WoW
for WildStar
for Solar2D
Documentation
for WoW
for WildStar
Reference
WoW
⦁ FrameXML
⦁ AddOns
⦁ API
⦁ WoW Lua
WildStar
⦁ AddOns
⦁ API
⦁ WildStar Lua
Engine
Tools
What links here
Related changes
Special pages
Page information
Site
Recent Changes
Editing
WoW:Object-oriented programming
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Example Class === This is the fully written class we have created through the above methods. It has a constructor, creates the required fields, and gives each instance two functions: isAlliance and isHorde, which returns true if the character's race is set to an Alliance or Horde race, respectively. It also has a function load(), which loads data given a Unit ID via the Blizzard API. Character = {}; Character.__index = Character; function Character:new() local self = {}; setmetatable(self, Character); self.name = "Unknown"; self.race = "Unknown"; self.class = "Unknown"; self.level = 0; return self; end function Character:load(uid) if ~UnitExists(uid) then return false; end self.name = UnitName(uid); self.race = UnitRace(uid); self.class = UnitClass(uid); self.level = UnitLevel(uid); return true; end function Character:isAlliance() if ( self.race == "Human" or self.race == "Night Elf" or self.race == "Dwarf" or self.race == "Gnome" or self.race == "Draenei" ) then return true; else return false; end end function Character:isHorde() if (self.race == "Unknown") then return false; else return ~self:isAlliance(); end end And we can quickly use this class to get information about our 40 raid members, and store them in a table: local units = {}; for x = 1, 40 do units[x] = Character:new(); units[x]:load("raid"..x); end
Summary:
Please note that all contributions to AddOn Studio are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
AddOn Studio Wiki:Copyrights
for details).
Submissions must be written by you, or copied from a public domain or similar free resource (see
AddOn Studio Wiki:Copyrights
for details).
Cancel
Editing help
(opens in new window)