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

Desktop not being drawn again.

Started by Midnightas, 30 December 2014 - 01:10 PM
Midnightas #1
Posted 30 December 2014 - 02:10 PM
Hello everyone, im making a system called Magnet Systems, but the clock if getting on my nerves.
It is supposed to update every .5 seconds and then is supposed to draw the desktop again, but its only drawn once.
This is my code:

-- Desktop
w, h = term.getSize()
cWhite = 1
cOrange = 2
cMagenta = 4
cLightBlue = 8
cYellow = 16
cLime = 32
cPink = 64
cGray = 128
cLightGray = 256
cCyan = 512
cPurple = 1024
cBlue = 2048
cBrown = 4096
cGreen = 8192
cRed = 16384
cBlack = 32768
formattedTime = "0"
ostime = os.time()
function drawDesktop()
term.setBackgroundColor(cLightGray)
term.setTextColor(cRed)
term.clear()
term.setCursorPos(1,1)
term.setBackgroundColor(cGray)
term.clearLine()
term.setBackgroundColor(cRed)
print("  ")
term.setCursorPos(w-8, 1)
term.setBackgroundColor(cGray)
term.setTextColor(cBlue)
print(formattedTime)
end
function startClock()
while true do
  formattedTime = textutils.formatTime(ostime, false)
  drawDesktop()
  sleep(1)
end
end
function drawSplash()
local frameone = paintutils.loadImage("/magnet/.magnetsplash1")
local frametwo = paintutils.loadImage("/magnet/.magnetsplash2")
paintutils.drawImage(frameone, 1, 1)
sleep(1)
paintutils.drawImage(frametwo, 1, 1)
sleep(1)
paintutils.drawImage(frameone, 1, 1)
sleep(1)
paintutils.drawImage(frametwo, 1, 1)
sleep(1)
end
drawSplash()
parallel.waitForAny(startClock)
The splash is drawn, then the desktop is drawn, but then the startClock function is supposed to keep drawing the desktop. But that is is not happening, can anyone help me?
Midnightas #2
Posted 30 December 2014 - 03:00 PM
Hello?

Sorry, i fixed it.
I placed ostime into the startClock function and it started working.
MKlegoman357 #3
Posted 30 December 2014 - 05:26 PM
One tip about colors. There is a colors API which basically gives you all the colors by their names. So instead of defining those colors by yourself you could do:


term.setBackgroundColor(colors.red)
term.clear()