View Single Post
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