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

Stops at "end" for second "if" and wants to end "while"

Started by Borka223, 14 October 2012 - 07:14 PM
Borka223 #1
Posted 14 October 2012 - 09:14 PM
I've written a clock program, but it simply won't work! The code is:

while true do
sleep(0.1)
if math.floor(os.time())==0 or math.floor(os.time())==12 then
c = 1
end
if math.floor(os.time())==1 or math.floor(os.time())==13 then
c = 2
end
if math.floor(os.time())==2 or math.floor(os.time())==14 then
c = 4
end
if math.floor(os.time())==3 or math.floor(os.time())==15 then
c = 8
end
if math.floor(os.time())==4 or math.floor(os.time())==16 then
c = 16
end
if math.floor(os.time())==5 or math.floor(os.time())==17 then
c = 32
end
if math.floor(os.time())==6 or math.floor(os.time())==18 then
c = 64
end
if math.floor(os.time())==7 or math.floor(os.time())==19 then
c = 128
end
if math.floor(os.time())==8 or math.floor(os.time())==20 then
c = 256
end
if math.floor(os.time())==9 or math.floor(os.time())==21 then
c = 512
end
if math.floor(os.time())==10 or math.floor(os.time())==22 then
c = 1024
end
if math.floor(os.time())==11 or math.floor(os.time())==23 then
c = 2048
end
rs.setBundledOutput("top", c)
end
and when I run it it outputs

bios:206: [string "clock"]:8: 'end' expected (to close 'while' at line 1)
Could I get answers as soon as I can? Thanks for any replies!
PixelToast #2
Posted 14 October 2012 - 09:22 PM
you have a ton of unecicary if functions
let me compress them for you

while true do
   rs.setBundledOutput("top",2^(math.floor(os.time()) % 12))
   sleep(1)
end
:3 xD
Borka223 #3
Posted 14 October 2012 - 09:24 PM
you have a ton of unecicary if functions
let me compress them for you

while true do
   rs.setBundledOutput("top",2^(math.floor(os.time()) % 12))
   sleep(1)
end
xD
LOL, fail. I usualy shorten code with maths, but my brain obviously failed this time.