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

FS API with background colors

Started by Admicos, 05 July 2014 - 07:38 AM
Admicos #1
Posted 05 July 2014 - 09:38 AM
Making it simple: Im making a os and i want to implement config. when i get number out of config and try it as a background. it just errors.

Code:

menu = 0
w, h = term.getSize()

rootdir = "AdmiOS/"
--API LOAD
os.loadAPI(rootdir .. "apis/gui")
os.loadAPI(rootdir .. "apis/osinfo")
--os.loadAPI(rootdir .. "apis/cfg")
--print("CONFIG API LOADED")
--API LOAD END
--GETCFG
local config = fs.open(rootdir .. "os.conf", "r")
bg = config.readLine()
config.close()


function desktop()
term.setBackgroundColor(bg)
term.clear()
term.setBackgroundColor(colors.lightBlue)
term.setCursorPos(1,1)
term.clearLine()
term.setTextColor(colors.white)
term.setBackgroundColor(colors.green)
term.setCursorPos(1,1)
print("Start")
end

function start()
term.setBackgroundColor(colors.blue)
term.setTextColor(colors.white)
term.setCursorPos(1,2)
print("          ")
sleep(0.1)
term.setCursorPos(1,3)
print("Shut Down ")
end
desktop()
while true do
local event, button, X, Y = os.pullEvent("mouse_click")
if X>=1 and X<=5 and Y==1 and button==1 then
menu = 1
start()
else
desktop()
end
end

The os.conf file just has a 8.

When i try to print bg it just says 8. Works fine
Cutecurtain #2
Posted 05 July 2014 - 09:45 AM
The problem is that the 8 that you load from the config file is a string. use the tonumber function to make it into a number.

Replace

bg = config.readLine()
with:

bg = tonumber(config.readLine())
Admicos #3
Posted 05 July 2014 - 10:03 AM
Thanks! Problem solved