View Single Post
03/22/15, 06:36 AM   #3
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by votan View Post
I think the problem is the DoesScriptNameExist function.
CLICK4INFO.sv.scripts is a indexed table (using table.insert)

The function should be like this:
Lua Code:
  1. local function DoesScriptNameExist(scriptName)
  2.     local scripts = CLICK4INFO.sv.scripts
  3.     for _, script in ipairs(scripts) do
  4.         if script.scriptName == scriptName then
  5.             return true
  6.         end
  7.     end
  8.     return false
  9. end

CU
Or you can replace table.insert and remove whole DoesScriptNameExist function:

Lua Code:
  1. function Click4Info_AddScript(self)
  2.     local scriptName = CLICK4INFO.nameEditBox:GetText()
  3.     local script = CLICK4INFO.scriptEditBox:GetText()
  4.  
  5.     if not script or script == "" then return end
  6.     if not scriptName or scriptName == "" then
  7.         scriptName = "New Script"
  8.     end
  9.  
  10.     debugMsg("Adding Script")
  11.  
  12.     local scripts = CLICK4INFO.sv.scripts
  13.     local uniqueScriptName = scriptName
  14.     local counter = 1
  15.  
  16.     while scripts[uniqueScriptName] ~= nil do
  17.         uniqueScriptName = ("%s (%d)"):format(scriptName, counter)
  18.         counter = counter + 1
  19.     end
  20.  
  21.     scripts[uniqueScriptName] = script
  22. end

Last edited by Garkin : 03/22/15 at 06:40 AM.
  Reply With Quote