Advertisement
theoriginalbit

ccConfig: Example — Resetting a Config on Error

Feb 14th, 2013
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.91 KB | None | 0 0
  1. os.loadAPI("/ccConfig")
  2.  
  3. local config = ccConfig.new("config.cfg", "Resetting a Config")
  4. local running
  5.  
  6. local function loadConfig()
  7.   config:load()
  8.  
  9.   running = config:getBoolean("canRun", true) -- put this value in the config after first run  "thisCausesError"
  10.  
  11.   config:save()
  12.   return true
  13. end
  14.  
  15. local ok, err = pcall(loadConfig)
  16.  
  17. if not ok then
  18.   print("Error ->"..err) -- tell the user what they did wrong
  19.   config:reset() -- this resets the configs back to the default values you provide, of course if it an error in your defaults this will do nothing, its mainly for when you have an error in the config caused by the users
  20.   config:save() -- save the defaults out to file
  21.   loadConfig() -- call our load again, this should work fine now unless its a problem with your defaults
  22. end
  23.  
  24. print("This should display whats in the configs:")
  25. print("canRun: "..tostring(running)) --> whats in config or false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement