Thread: minified LUA
View Single Post
05/27/14, 08:56 AM   #4
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by hulksmash View Post
Is there any issues with only providing the minified version of your LUA source? For example, in my SWAPS addon I am using the minified source. I am interested in knowing if it will conflict with other addons due to variables name changes or if there are any other potential problems.
If you don't use global variables, there shouldn't be any problem.
The only issue I can think of will be with bug reports as it will be very hard to get any useful information from UI error dialog.

A few comments:
It is good practice to unregister events you do not need. As you are trying to make your code very small, you can register for EVENT_ADD_ON_LOADED as follows:
Lua Code:
  1. local ev,a=EVENT_MANAGER,"swaps"
  2. ev:(a,EVENT_ADD_ON_LOADED,function(c,n)if n==a then l()ev:UnregisterForEvent(a,c)end)
("l" is your OnLoad function.)

Also to keep minimal length of code, you do not need to define names for your controls:
Lua Code:
  1. a.renameModal=swaps.Chain(b:CreateTopLevelWindow()):SetDimensions(450,200):SetAnchor(CENTER,GuiRoot,CENTER,0,0):SetHidden(true).__END
  2.  
  3. a.renameModal.bg=swaps.Chain(b:CreateControl(nil,a.renameModal,CT_BACKDROP)):SetEdgeColor(.3,.3,.3,.5):SetCenterColor(.1,.1,.1,.99):SetAnchor(TOPLEFT,a.renameModal,TOPLEFT,0,0):SetDimensions(450,200).__END
Note: If you create control from virtual, it sometimes needs to have defined name because of child controls that use "$(parent)" or "$(grandparent)" in their name.

You are using:
Lua Code:
  1. zo_callLater(function() d("Loaded -- Swap Skills -- AddOn by @HulkSmashWarrior") end, 320)
You can't be sure that this message will by displayed for everyone as loading times are different for each player. It is better to print it from function registered to EVENT_PLAYER_ACTIVATED. Or do not print it at all, as I do not like chat spam .
  Reply With Quote