This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
LordIkol's profile picture

[Lua][loadApi] Api not Loading, Bug or wrong Code?

Started by LordIkol, 14 April 2013 - 10:05 AM
LordIkol #1
Posted 14 April 2013 - 12:05 PM
Hi together,

For the Program im working on, at the moment, i would like to use the ccConfig API, from bit.
to get known how to work with it, i wanted to check the example File and play with it a bit.
But its not working. Infos as follwing:

Setup:
- API file is in the Main Folder of the Computer
- named ccConfig without any extention

Error: line 6 attempt to index ? (a nil value)

Other Notes
- added an empty file Named config.cfg – Same error
- when i change the first line to os.loadAPI("blabla") or os.loadAPI(" ") i dont get an error
- tried to use os.loadAPI("ccConfig") instead of os.loadAPI("/ccConfig")

i think loadapi should give an error if i try to load a file that does not exist but im not sure
maybe you can help

edit: forgot the code its the example code from bit :D/>



os.loadAPI("/ccConfig")

term.clear()
term.setCursorPos(1,1)

local conf = ccConfig.new("config.cfg")
local running
local msg
local rate
local bgcolor
local txtcolor

local function loadConfig()
  conf:load()

  running = conf:getBoolean("canRun", "no")
  msg = conf:getString("welcomeMessage", "Hello World")
  rate = conf:getNumber("refreshRate", 2.5)
  bgcolor = conf:getColor("background", colors.black)
  txtcolor = conf:getColour("text", "colors.white")


  conf:addCommentForKey("canRun", "Tells the program if it is allowed to run")
  conf:addCommentForKey("refreshRate", "Tells the program how often to check inputs again")

  conf:save()
end

local function resetConfig()
  conf:reset()
  conf:save()
end

loadConfig()

print("This should display whats in the configs:")
print("canRun: "..tostring(running)) --> whats in config or false
print("msg: "..msg) --> whats in config or "Hello World"
print("rate: "..rate) --> whats in config or 2.5
print("bg: "..bgcolor)
print("text: "..txtcolor)
print("canRun key exists: "..tostring(conf:containsKey("canRun")))
print("thisThing key exists: "..tostring(conf:containsKey("thisThing")))

resetConfig()
loadConfig()

print("\nThis should display whats the default values are:")
print("canRun: "..tostring(running)) --> whats in config or false
print("msg: "..msg) --> whats in config or "Hello World"
print("rate: "..rate) --> whats in config or 2.5
print("bg: "..bgcolor)
print("text: "..txtcolor)
print("canRun key exists: "..tostring(conf:containsKey("canRun")))
print("thisThing key exists: "..tostring(conf:containsKey("thisThing")))


Thanks in advance
Loki
Edited on 14 April 2013 - 10:36 AM
LordIkol #2
Posted 14 April 2013 - 12:39 PM
I could solve it.
I dont know why but for some reason he did not like the downloaded txt file.
i renamed it and redownloaded it before i posted already and the error was still the same.

after testing a bit around with the lua console and the loadapi i deleted the API
Copied the API Code from Pastebin
pasted it into Notepad++ and saved it

that worked now he accepts the API

greets Loki