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

Crash in my Graphic Interface Settings Program

Started by MyZoom, 31 May 2014 - 07:38 PM
MyZoom #1
Posted 31 May 2014 - 09:38 PM
Hey, so I made a program for changing the background color of my desktop but it keeps crashing,
can you guys help me please ? :)/>


slc = 0
tBarC = 128
tBartC = 1
term.clear()

function drawDesktop()
  term.clear()
  bground = paintutils.loadImage("/DogeOs/Images/settings.nfp")
  paintutils.drawImage(bground,1,1)
  term.setTextColor(colors.black)
  term.setCursorPos(2,3)
  print("Select any color for you background")
  term.setCursorPos(2,11)
  print(" If you want to change your username")
  print(" or your password, simply go to:")
  print(" /DogeOs/API/(username or password)")
  print(" using Finder and follow the instructions")

end

drawDesktop()
while true do
local event, button, X, Y = os.pullEventRaw()
  if slc == 0 then
    if event == "mouse_click" then
      if X >=2 and X <=8 and Y==1 and button ==1 then
      slc = 1
        else
        drawDesktop()
-- ORANGE
      if X >=2 and X <=3 and Y >=5 and Y <=6 and button ==1 then
         h = fs.open("/DogeOs/API/color")
         h.writeLine("backg = 2")
         h.close()
         os.reboot()
-- PINK
      elseif X >=5 and X <=6 and Y >=5 and Y <=6 and button ==1 then
fs.delete("/DogeOs/API/color")
h = fs.open("/DogeOs/API/color")
h.write("backg = 4")
h.close()
os.reboot()
-- LIGHT BLUE
      elseif X >=8 and X <=9 and Y >=5 and Y <=6 and button ==1 then
fs.delete("/DogeOs/API/color")
h = fs.open("/DogeOs/API/color")
h.write("backg = 8")
h.close()
os.reboot()
-- YELLOW
      elseif X >=11 and X <12 and Y >=5 and Y <=6 and button ==1 then
fs.delete("/DogeOs/API/color")
h = fs.open("/DogeOs/API/color")
h.write("backg = 16")
h.close()
os.reboot()
-- LIGHT GREEN
      elseif X >=14 and X <=15 and Y >=5 and Y <=6 and button ==1 then
fs.delete("/DogeOs/API/color")
h = fs.open("/DogeOs/API/color")
h.write("backg = 32")
h.close()
os.reboot()
-- LIGHT PINK
      elseif X >=17 and X <=18 and Y >=5 and Y <=6 and button ==1 then
fs.delete("/DogeOs/API/color")
h = fs.open("/DogeOs/API/color")
h.write("backg = 64")
h.close()
os.reboot()
-- LIGHT GRAY
      elseif X >=20 and X <=21 and Y >=5 and Y <=6 and button ==1 then
fs.delete("/DogeOs/API/color")
h = fs.open("/DogeOs/API/color")
h.write("backg =256 ")
h.close()
os.reboot()
-- CYAN
      elseif X >=3 and X <=4 and Y >=8 and Y <=9 and button ==1 then
fs.delete("/DogeOs/API/color")
h = fs.open("/DogeOs/API/color")
h.write("backg = 512")
h.close()
os.reboot()
-- PURPLE
      elseif X >=6 and X <=7 and Y >=8 and Y <=9 and button ==1 then
fs.delete("/DogeOs/API/color")
h = fs.open("/DogeOs/API/color")
h.write("backg = 1024")
h.close()
os.reboot()
-- BLUE
      elseif X >=9 and X <=10 and Y >=8 and Y <=9 and button ==1 then
fs.delete("/DogeOs/API/color")
h = fs.open("/DogeOs/API/color")
h.write("backg = 2048")
h.close()
os.reboot()
-- BROWN
      elseif X >=12 and X <=13 and Y >=8 and Y <=9 and button ==1 then
fs.delete("/DogeOs/API/color")
h = fs.open("/DogeOs/API/color")
h.write("backg = 4096")
h.close()
os.reboot()
-- GREEN
      elseif X >=15 and X <=16 and Y >=8 and Y <=9 and button ==1 then
fs.delete("/DogeOs/API/color")
h = fs.open("/DogeOs/API/color")
h.write("backg = 8192")
h.close()
os.reboot()
-- RED
      elseif X >=18 and X <=19 and Y >=8 and Y <=9 and button ==1 then
fs.delete("/DogeOs/API/color")
h = fs.open("/DogeOs/API/color")
h.write("backg = 16384")
h.close()
os.reboot()
-- END OF COLORS

                end     
            end 
        end
    end
end

BlockSmith #2
Posted 01 June 2014 - 01:45 AM
Look at your if, elseif statements. It looks like they are out of order up top.
Edited on 31 May 2014 - 11:47 PM
Bomb Bloke #3
Posted 01 June 2014 - 03:45 AM
Line 32:

h = fs.open("/DogeOs/API/color")

"fs.open()" expects you to pass it two strings - the name of the file you wish to open, and the mode in which you wish to open it. You're forgetting the mode.

Try:

h = fs.open("/DogeOs/API/color","w")
MyZoom #4
Posted 01 June 2014 - 07:57 AM
Thanks it works perfectly :D/> !
BlockSmith #5
Posted 03 June 2014 - 12:28 AM
Nice catch. I haven't jumped into the fs Much.