View Single Post
07-26-18, 06:51 PM   #2
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
That's the issue. The local variable is nil. It needs to be a table before you assign any indexes.

You also need to create a separate frame for each button, but that top line in the loop will reuse the same frame over and over again, only creating one button that will either keep moving over 5 pixels or error trying to create a second button because you can't anchor a frame to itself.

Change these two lines:

Lua Code:
  1. local mapButton;
  2. mapButton[i]=DragExample or CreateFrame("Button", "DragExample", UIParent, "ActionButtonTemplate,SecureActionButtonTemplate,SecureHandlerDragTemplate")

To these:

Lua Code:
  1. local mapButton = {};
  2. mapButton[i]=CreateFrame("Button", "DragExample" .. i, UIParent, "ActionButtonTemplate,SecureActionButtonTemplate,SecureHandlerDragTemplate")

This makes mapButton an empty table, ready to accept the indexes you're trying to assign, and properly creates a separate frame for each button with the index appended to the global name so they can all coexist.
  Reply With Quote