Posted 16 October 2014 - 12:42 AM
Hello! So I'm working on a config API (It'll be pretty simple to do once I get this bug figured out) I get an error on line 60 and all similar lines due to the configData returning nil (Yes, I am calling the configSet before running the other codes) Another error I found when debugging the line 60 error is that no matter what the code dosen't work. In the code I set configData to "test[Banana]" and ran this code in a separate file:
What I would get is just a blank printed line.
Thanks for any help I get!
My code:
(Not sure why copying isn't copying my formatting.. sorry if it's hard to read)
EDIT:
Want the formatting? Check it out on pastebin. http://pastebin.com/0GUjr64m
os.loadAPI("config")
print(config.getString("test"))
What I would get is just a blank printed line.
Thanks for any help I get!
My code:
Spoiler
--[[
Coded by Cameron Lund
Bukkit: ShadowDisruptor
BukkitDev: ShadowDisrupter
Minecraft: footballfan12
License
Fair-use
--]]
configSet = false
function setConfig(config)
configSet = true
if fs.exists(config) then
if not configFile == nil then
configFile.close()
configFile = fs.open((config), "r")
else
configFile = fs.open((config), "r")
end
if not configFileWrite == nil then
configFileWrite.close()
configFileWrite = fs.open((config), "a")
else
configFileWrite = fs.open((config), "a")
end
return true
else
return nil
end
configData = configFile.readAll()
end
function reloadConfig()
if configSet == true then
configData = configFile.readAll()
return true
else
return nil
end
end
function doesExist(node)
if configSet == true then
if not string.find(node, configData) == nil then
return true
else
return false
end
else
return nil
end
end
function getString(node)
if configSet == true then
if string.find(".", node) then
else
if not string.find(node.."[", configData) == nil then
pos2, pos1 = string.find(node.."[",configData)
pos3, pos2 = string.find("]",configData,pos1)
theString = string.sub(configData,pos1,pos2)
return theString
else
return nil
end
end
else
return nil
end
end
EDIT:
Want the formatting? Check it out on pastebin. http://pastebin.com/0GUjr64m
Edited on 15 October 2014 - 10:46 PM