« Some Javascript | Main | Tree structure »
June 9, 2009
Learning notes of my addon project
I have been working on a "warcraft" project recently, and learned something about XML and lua. I was impressed warcraft can load lua funtions by reading throught the xml file. It seems that xml file can hold sorted values. below are my learning notes, we can see some interesting features.
Learning Notes
1. Start Xml flie for WoW
1
3
2.Loading a lua file
1.
2. In "toc" file, write: ---------> Like a "header" of C++
## Interface: 20400 ---------> Game version 游戏版本
## Title: NewAddon
## DefaultState: Enabled
## LoadOnDemand: 0
## SavedVariablesPerCharacter:
Filename.xml --------->this header includes a xml
Filename.lua --------->and a lua fiel
3. Frame:
Frame --------->can be the class of parent frames
Button --------->button
EditBox --------->like labels in HTML, but more like a layer
GameTooltip --------->Mouse event
ColorSelect --------->Choose color
MessageFrame ---------> also like labels .. Sometimes it is very similar as edit box
Minimap --------->Loading mini map in WoW, including the battle ground .
Model --------->it is for 3D animations of the characters. I haven't really used it
MovieFrame --------->I don't know. I think it is for 3D image ( a functionality in WOW to show a target's icon, it shows 3D animation)
ScrollFrame --------->a frame can scroll up and down, like a textarea in HTML.
ScrollingMessageFrame --------->same as above, but only showing text
SimpleHTML --------->every thing in this tag will be HTML
Slider --------->a slider bar, like a bar to set the volumn
StatusBar --------->a bar , to show health , mana, or casting skills.
4.Programming in Lua
1. Over write Blizzard's functions
2 old_add = add; -- Save the original add function
3 add = function(a,b) -- add has a new function
4 if ( old_add(a,b) == 0 ) then return nil end
5 return a + b
6 end
--. define another function with the same name
7 function add(a,b) -- same function as above
8 local ret = a + b
9 if ( ret == 0 ) then return nil end
10 return ret
11 end
5. Use ":"
This is how to call a method of an object, not using "." but ":"
Like : frame:Show();
6. How to drag an iterm in WoW
---------------When Click the mouse down----------------
if not (TargetRange_moving or TargetRange_IsLocked() ) then
TargetRange_moving = this;
this:StartMoving();
end
---------------When loose the mouse button----------------
if TargetRange_moving == this then
TargetRange_moving = nil; this:StopMovingOrSizing();
end
------------------Drag-----------------------------------
if TargetRange_moving == this then
TargetRange_moving = nil;
this:StopMovingOrSizing();
end
Posted by chenz at June 9, 2009 9:33 AM