ComputerCraft loops

Discussion in 'Alice (Minecraft)' started by Tonius, 25 July 2012.

  1. Tonius

    Tonius 555 Eternal Server Error

    Joined:
    30 January 2012
    Messages:
    480
    Likes Received:
    392
    Hi there,

    I've seen that you can now use ComputerCraft computers to read the charge from a BatBox, an MFE or an MFSU. Very happy to see this, I immediately made a program that shows the charge level of my MFSU with coloured lamps. This program is supposed to read the charge level and update every 2 seconds. This is the program:

    Code:
    mfsu = peripheral.wrap('right')
     
    while true do
      charge = mfsu.getChargeLevel()
     
      if charge == 0.00 then
        rs.setBundledOutput('left', 0)
      elseif (charge <= 0.33) and (charge > 0.00) then
        rs.setBundledOutput('left', colours.red)
      elseif (charge > 0.33) and (charge <= 0.66) then
        rs.setBundledOutput('left', colours.red+colours.yellow)
      elseif (charge > 0.66) and (charge <= 0.90) then
        rs.setBundledOutput('left', colours.red+colours.yellow+colours.lime)
      elseif (charge > 0.90) and (charge <= 1.00) then
        rs.setBundledOutput('left', colours.red+colours.yellow+colours.lime+colours.green)
      end
     
      sleep(2)
    end
    The colours in the bundled output are same colours as the colours of the lamps that receive the redstone signals.

    Anyway, the problem with this program is that the program only loops once, even though it is supposed to loop infinitely. If I try to use a for loop or a repeat loop, the same thing happens, it only loops once.

    Does this happen because there is something wrong with my code, or are loops disabled on the server?

    TL;DR: While, for and repeat loops do not work in my code, are loops disabled on ComputerCraft computers?