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:Function arguments
(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!
== It's quite simple really... == Functions can have arbitrarily defined arguments defined in the opening line and subsequently used within the body of the function. Your parameters can be called any valid Lua name. Below is a simple function without arguments, followed by another function that calls on the first: function MyAddon_Mimic() DEFAULT_CHAT_FRAME:AddMessage("Hello World!") end function MyAddon_Call() MyAddon_Mimic() end Now the same function with arguments (you can define any number of arguments): function MyAddon_Mimic(arg1) DEFAULT_CHAT_FRAME:AddMessage("Hello " .. arg1) end function MyAddon_Call() MyAddon_Mimic("Buddy!") end Whereas the first example would've simply printed "Hello World!" to the chat window, the second example will now print "Hello Buddy!" However, arg1 is a pretty non-discriptive argument name (and we only used one). Let's try something more interesting: function MyAddon_Mimic(who, send) local posX, posY = [[API GetPlayerMapPosition|GetPlayerMapPosition]](who); if send==1 then DEFAULT_CHAT_FRAME:AddMessage(who .. " is currently at location " .. posX .. "," .. posY) end end function MyAddon_Call() MyAddon_Mimic("player", 1) MyAddon_Mimic("party1", 1) MyAddon_Mimic("party2", 0) end Here, our little addon will now print the location of our player and our first party member, but while it will get the location of party member 2, it won't print it. [[Category: HOWTOs|Function Arguments]]
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)