Posted 20 November 2013 - 08:20 AM
Hey, got this code
and this is the DesignUtil Api
When I click in the program, the click is identified, and getSelection is called, but the bg wont change. what could be thae cause and the fix?
Spoiler
os.loadAPI("OsOne/Apis/DesignUtil");
background=DesignUtil.getDesign()
term.setTextColor(colors.lightGray)
local cols = {1, 2, 4, 8, 16, 32, 64, 512, 1024, 2048, 4096, 8192, 16384, 32768}
local selector={
row1="v";
row2="^";
x=11;
y=9;
}
function getSelection(x)
if x>=11 and x<13 then
DesignUtil.setDesign(0)
background=DesignUtil.getDesign()
end
if x>=13 and x<15 then
DesignUtil.setDesign(1)
--background=DesignUtil.getDesign()
paintutils.drawImage(background,1,1)
end
end
function detectClick(xPos,yPos)
if yPos==9 then
selector.x=xPos;
getSelection(xPos)
end
end
function printSelector()
term.setBackgroundColor(colors.gray)
term.setCursorPos(selector.x,selector.y-1)
print(selector.row1)
term.setCursorPos(selector.x,selector.y+1)
print(selector.row2)
end
while true do
paintutils.drawImage(background,1,1)
term.setCursorPos(2,4)
print("Choose a color and name your computer, you will be able to personalize more later.")
term.setCursorPos(10,8)
term.setBackgroundColor(colors.gray)
print(" ")
term.setCursorPos(10,9)
term.setBackgroundColor(colors.gray)
print(" ")
term.setCursorPos(10,10)
term.setBackgroundColor(colors.gray)
print(" ")
term.setBackgroundColor(DesignUtil.getColor())
term.setCursorPos(11,9)
for i,v in ipairs(cols) do
term.setBackgroundColor(v)
term.write(" ")
end
printSelector();
term.setBackgroundColor(DesignUtil.getColor())
sleep(1)
local event, button, X, Y = os.pullEvent("mouse_click")
detectClick(X,Y)
end
and this is the DesignUtil Api
Spoiler
local fileColorConfig=nil
local backGround=nil
local fileData = {}
function getDesign()
fileColorConfig=fs.open("OsOne/Prefrences/Design.prefrence","r");
local line = fileColorConfig.readLine()
repeat
table.insert(fileData,line)
line = fileColorConfig.readLine()
until line == nil
fileColorConfig.close()
if fileData[1]=="0" then backGround=paintutils.loadImage("SystemResources/GraphicsResources/backgrounds/whiteBack.nfp") end
if fileData[1]=="1" then backGround=paintutils.loadImage("SystemResources/GraphicsResources/backgrounds/orangeBack.nfp") end
if fileData[1]=="2" then backGround=paintutils.loadImage("SystemResources/GraphicsResources/backgrounds/darkPinkBack.nfp") end
if fileData[1]=="3" then backGround=paintutils.loadImage("SystemResources/GraphicsResources/backgrounds/lightBlueBack.nfp") end
if fileData[1]=="4" then backGround=paintutils.loadImage("SystemResources/GraphicsResources/backgrounds/goldenBack.nfp") end
if fileData[1]=="5" then backGround=paintutils.loadImage("SystemResources/GraphicsResources/backgrounds/limeBack.nfp") end
if fileData[1]=="6" then backGround=paintutils.loadImage("SystemResources/GraphicsResources/backgrounds/pinkBack.nfp") end
if fileData[1]=="9" then backGround=paintutils.loadImage("SystemResources/GraphicsResources/backgrounds/cyanBack.nfp") end --because 8 is topbar color and 7 is button BG
if fileData[1]=="a" then backGround=paintutils.loadImage("SystemResources/GraphicsResources/backgrounds/purpleBack.nfp") end
if fileData[1]=="b" then backGround=paintutils.loadImage("SystemResources/GraphicsResources/backgrounds/blueBack.nfp") end
if fileData[1]=="c" then backGround=paintutils.loadImage("SystemResources/GraphicsResources/backgrounds/brownBack.nfp") end
if fileData[1]=="d" then backGround=paintutils.loadImage("SystemResources/GraphicsResources/backgrounds/greenBack.nfp") end
if fileData[1]=="e" then backGround=paintutils.loadImage("SystemResources/GraphicsResources/backgrounds/redBack.nfp") end
fileColorConfig.close()
return backGround;
end
function setDesign(design)
fileColorConfig=fs.open("OsOne/Prefrences/Design.prefrence","w");
fileColorConfig.write(design.."")
fileColorConfig.close()
end
function getColor()
fileColorConfig=fs.open("OsOne/Prefrences/Design.prefrence","r");
local fileDataI={}
local line = fileColorConfig.readLine()
repeat
table.insert(fileDataI,line)
line = fileColorConfig.readLine()
until line == nil
fileColorConfig.close()
if fileDataI[1]=="0" then return colors.white end
if fileDataI[1]=="1" then return colors.orange end
if fileDataI[1]=="2" then return colors.magenta end
if fileDataI[1]=="3" then return colors.lightBlue end
if fileDataI[1]=="4" then return colors.yellow end
if fileDataI[1]=="5" then return colors.lime end
if fileDataI[1]=="6" then return colors.pink end
if fileDataI[1]=="9" then return colors.cyan end --because 8 is topbar color and 7 is button BG
if fileDataI[1]=="a" then return colors.purple end
if fileDataI[1]=="b" then return colors.blue end
if fileDataI[1]=="c" then return colors.brown end
if fileDataI[1]=="d" then return colors.green end
if fileDataI[1]=="e" then return colors.red end
end
When I click in the program, the click is identified, and getSelection is called, but the bg wont change. what could be thae cause and the fix?