I've got your original script sort of working. It is reading the prefs but it's not perfect yet.
EDIT: Through away that code above. I don't think it works the way you think it should.
The problem is too many nested ifs that were not closed properly. You MUST keep the indenting proper. If I don't do that all the time in some of my scripts... ignore me. Do what I say not what I do.
Indenting properly helps you see if the structure of the script is correct. The reason the variables weren't coming up correctly was that some parts of the script were in the wrong spot.
An if/then statement must be indented properly to read it. It doesn't change how the script works it's just for a visual reference. I choose NOT to indent "else" and "elseif". It's just easier for me to read the code. Most lua references say to indent the else and else if.
You may have an overly complicated if/then set up here that could be simplified. It is so easy to get lost in the code I need to study it to see how to make it simpler. One of the lines may extend longer than this forum window can display so it might run to another line.
This is a modified version of your "Run" function. there is nothing else after this. I removed all the other code below the run function. With this code the saved prefs are loaded but the path cuts of at the Anime Studio folder instead of the scripts folder... is that correct? Anyway, remember to indent properly. It will make life so much easier.
I've put in comments to match up the start and end of each if and while statement. You should get a program like jEdit that will automatically indent or at least make it easier to indent. Plus you can set it up to "collapse" the lines based on the indent allowing you to "hide" huge chunks of code and also check for proper structure.
Code: Select all
function Syn_Addons:Run(moho) -- function start
if (self.bpath == nil or self.bpath == "") then -- first if start
check1 = LM.GUI.Alert(LM.GUI.ALERT_INFO, "Syn_Addons needs to know where your tool list is located.", "Please navigate to '...Anime Studio\\scripts\\tool\\_tool_list.txt'", nil, "OK", "Cancel", nil)
if (check1 == 1)then -- second if start
return
else -- part of second if needs no end
local path = LM.GUI.OpenFile("Select ...scripts\\tool\\_tool_list.txt")
if (path == "")then -- third if start
return
elseif (string.sub(path, -14) == "_tool_list.txt") then
self.tlpath = path
elseif (path ~= "" or nil) then
while (string.sub(path, -14) ~= "_tool_list.txt") do -- while start
check2 = LM.GUI.Alert(LM.GUI.ALERT_INFO, "Wrong file.", "Please select again.", nil, "OK", "Cancel", nil)
if (check2 == 1) then -- fourth if start
break
elseif (check2 == 0) then
local path = LM.GUI.OpenFile("Select ...scripts\\tool\\_tool_list.txt")
if (path == "") then -- fifth if start
return
elseif (string.sub(path, -14) == "_tool_list.txt") then
self.tlpath = path
break
end -- fifth if end
end -- fourth if end
end -- while end
end -- third if end
end -- second if end
end -- first if end
if (self.tlpath ~= nil) then
if (string.sub(self.tlpath, -14) == "_tool_list.txt") then
local path = string.sub(self.tlpath, 1, - 28)
if (path ~= "") then
self.bpath = path
end
end
end
if (self.tlpath ~= nil) then
print(self.tlpath)
end
if (self.bpath ~= nil) then
print(self.bpath)
end
end -- function end