Thread Tools Display Modes
08-03-18, 12:36 PM   #1
candrid
Premium Member
 
candrid's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 61
Red face Creating a Development Tutorial

Hey Friends!

So many people help me understand what some of the development things mean. I decided I would heavily comment code and try to explain what I am doing/meaning but I did not want to stop there. I am going to make a tutorial on creation. Below is some example code, showing this idea, anything you want to see?

Code:
local addonName, addonData = ... -- This line means you are setting two local variables, addonName and addonData to equal multiple things.

-- Configuration
local camSpeed = 0.4  -- The speed of the rotation, higher is faster
local returnView = true -- This makes the camera return to its original position when you return from AFK.

local isAFK = false -- When this is default false the player is active, we use the trigger to switch it on.
local smoothCamera -- Creates the Variable "smoothCamera."

-- Functions (the things the addon does)
local function beginMovement (speed)
	smoothCamera = GetCVar("cameraSmoothStyle") -- the CVar "cameraSmoothStyle" determines the style of the camera.
	if (returnView) then -- An if statement is like a true and false, a yes or no.
		SaveView(5)
	end -- Ends the if statement.

Please feel free to correct me in errors.

Thanks in advance!

Last edited by candrid : 08-03-18 at 03:44 PM.
  Reply With Quote
08-03-18, 01:21 PM   #2
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
There is lots of good stuff on Wowpedia/Gamepedia: https://wow.gamepedia.com/Wowpedia:I..._customization
  Reply With Quote
08-03-18, 01:27 PM   #3
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Also, your definition of "Global variable" is wrong.
Lua Code:
  1. someVar -- global variable
  2. local someVar -- local variable to file scope
  3. function MyFunc() -- global function
  4. local function MyFunc() -- local function to file scope
  5.  
  6. -- addonName is the string name of your addon, like "BigWigs" or "My Awesome Addon"
  7. -- addonData is the private table passed to each Lua file within the same addon. useful for things like localization through multiple Lua files
  8. -- ... is a variable argument, or vararg
  9. local addonName, addonData = ...
  Reply With Quote
08-03-18, 03:00 PM   #4
candrid
Premium Member
 
candrid's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 61
Originally Posted by myrroddin View Post
Also, your definition of "Global variable" is wrong.
Lua Code:
  1. someVar -- global variable
  2. local someVar -- local variable to file scope
  3. function MyFunc() -- global function
  4. local function MyFunc() -- local function to file scope
  5.  
  6. -- addonName is the string name of your addon, like "BigWigs" or "My Awesome Addon"
  7. -- addonData is the private table passed to each Lua file within the same addon. useful for things like localization through multiple Lua files
  8. -- ... is a variable argument, or vararg
  9. local addonName, addonData = ...
Awesome thanks!
  Reply With Quote
08-03-18, 03:23 PM   #5
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Originally Posted by candrid View Post
If statements must end on the same "line" they start per beginning. Example here. They line up vertically. That is a "Block."
Lua Code:
  1. -- ...
  2.     if (returnView) then -- An if statement is like a true and false, a yes or no.
  3.         SaveView(5)
  4.     end -- If statements must end on the same "line" they start per beginning. Example here. They line up vertically. That is a "Block."

No, they don't. end means it's the end of the scope, but Lua is not sensitive to indentation. You can just as easily write your entire addon on one line and it would still work, just be a clusterfuck to read and understand.

Lua Code:
  1. if (returnView) then SaveView(5) end
__________________
  Reply With Quote
08-03-18, 03:43 PM   #6
candrid
Premium Member
 
candrid's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 61
Originally Posted by MunkDev View Post
Lua Code:
  1. -- ...
  2.     if (returnView) then -- An if statement is like a true and false, a yes or no.
  3.         SaveView(5)
  4.     end -- If statements must end on the same "line" they start per beginning. Example here. They line up vertically. That is a "Block."

No, they don't. end means it's the end of the scope, but Lua is not sensitive to indentation. You can just as easily write your entire addon on one line and it would still work, just be a clusterfuck to read and understand.

Lua Code:
  1. if (returnView) then SaveView(5) end
Thank you! I did not know that.
  Reply With Quote
08-03-18, 03:58 PM   #7
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
You forgot to close your function with an end.

myrroddin already explained to you what the variables in your vararg portion will be. I just wanted to give you reference on what a vararg is. https://www.lua.org/pil/5.2.html
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
08-03-18, 06:07 PM   #8
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
Originally Posted by MunkDev View Post
Lua Code:
  1. -- ...
  2.     if (returnView) then -- An if statement is like a true and false, a yes or no.
  3.         SaveView(5)
  4.     end -- If statements must end on the same "line" they start per beginning. Example here. They line up vertically. That is a "Block."

No, they don't. end means it's the end of the scope, but Lua is not sensitive to indentation. You can just as easily write your entire addon on one line and it would still work, just be a clusterfuck to read and understand.

Lua Code:
  1. if (returnView) then SaveView(5) end
This reminds me of the abomination I made my NoCombatText addon into years ago when I was in the prime of learning Lua.

The following is a valid addon, using code tags instead of highlight tags for maximum effect:

Code:
local b,c,d,e,f,g,h,j,k,l,n,r,s,u,v,w,y,z=COMBAT,nil,EVENTS_LABEL,PET,
CreateFrame('frame'),'|cff00ff00',PetFrame,PLAYER,'player',PlayerFrame,
'NoCombatText','|cffff0000',' ','UNIT_COMBAT',{j=1,o=1,e=1,},SlashCmdList,
VIDEO_OPTIONS_DISABLED,VIDEO_OPTIONS_ENABLED function f:p(m)nctsv=v for i=1,
NUM_CHAT_WINDOWS do c=_G['ChatFrame'..i]if c:IsEventRegistered('CHAT_MSG_SYSTEM'
)then c:AddMessage('|cffffff00'..n..': '..string.lower(m))end end end function
f:q(x)x:UnregisterEvent(u)end SLASH_NCTPL1='/playerct'function w:NCTPL()if v.j
then l:RegisterUnitEvent(u,k,'vehicle')v.j=nil f:p(j..s..b..s..d..s..r..z)else
f:q(l)v.j=1 f:p(j..s..b..s..d..s..g..y)end end SLASH_NCTPE1='/petct'function
w:NCTPE()if v.e then h:RegisterUnitEvent(u,'pet',k)v.e=nil f:p(e..s..b..s..d..
s..r..z)else f:q(h)v.e=1 f:p(e..s..b..s..d..s..g..y)end end f:RegisterEvent(
'ADDON_LOADED')f:SetScript('OnEvent',function(_,_,a)if a==n and nctsv then
v=nctsv nctsv=nil end if v.j then f:q(l)end if v.e then f:q(h)end nctsv=v end)
I still tend to ignore common organization methods like spacing things or using more lines, and this addon is still somewhat of a giant mess of "compact code" even now, but this is a great reminder about how far I've come.
  Reply With Quote
08-12-18, 11:37 AM   #9
JDoubleU00
A Firelord
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 463
Originally Posted by Kanegasi View Post
This reminds me of the abomination I made my NoCombatText addon into years ago when I was in the prime of learning Lua.

The following is a valid addon, using code tags instead of highlight tags for maximum effect:

Code:
local b,c,d,e,f,g,h,j,k,l,n,r,s,u,v,w,y,z=COMBAT,nil,EVENTS_LABEL,PET,
CreateFrame('frame'),'|cff00ff00',PetFrame,PLAYER,'player',PlayerFrame,
'NoCombatText','|cffff0000',' ','UNIT_COMBAT',{j=1,o=1,e=1,},SlashCmdList,
VIDEO_OPTIONS_DISABLED,VIDEO_OPTIONS_ENABLED function f:p(m)nctsv=v for i=1,
NUM_CHAT_WINDOWS do c=_G['ChatFrame'..i]if c:IsEventRegistered('CHAT_MSG_SYSTEM'
)then c:AddMessage('|cffffff00'..n..': '..string.lower(m))end end end function
f:q(x)x:UnregisterEvent(u)end SLASH_NCTPL1='/playerct'function w:NCTPL()if v.j
then l:RegisterUnitEvent(u,k,'vehicle')v.j=nil f:p(j..s..b..s..d..s..r..z)else
f:q(l)v.j=1 f:p(j..s..b..s..d..s..g..y)end end SLASH_NCTPE1='/petct'function
w:NCTPE()if v.e then h:RegisterUnitEvent(u,'pet',k)v.e=nil f:p(e..s..b..s..d..
s..r..z)else f:q(h)v.e=1 f:p(e..s..b..s..d..s..g..y)end end f:RegisterEvent(
'ADDON_LOADED')f:SetScript('OnEvent',function(_,_,a)if a==n and nctsv then
v=nctsv nctsv=nil end if v.j then f:q(l)end if v.e then f:q(h)end nctsv=v end)
I still tend to ignore common organization methods like spacing things or using more lines, and this addon is still somewhat of a giant mess of "compact code" even now, but this is a great reminder about how far I've come.
Clearly a wall of text.
__________________
Author of JWExpBar and JWRepBar.
  Reply With Quote

WoWInterface » Developer Discussions » Tutorials & Other Helpful Info. » Creating a Development Tutorial

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off