Chunk timmer

Discussion in 'ComputerCraft Programming' started by fxstriker, May 6, 2013.

  1. fxstriker

    fxstriker Good Bye skcraft.

    Joined:
    Jan 14, 2012
    Messages:
    259
    Likes Received:
    35
    Today i wrote a small program for use with chunk loaders.

    if you wanted to run them for a task that would take x amount of time and therefore only need the chunk loaded for say 3 hours then this program would be perfect fully tested and working.

    some quick things to note:
    by default it has color this can be changed or removed and is only compatible with advanced computers just removed the first line.

    the output defaults to on and needs to be inverted this is in case the program crashes or server restarts .

    by default you need to type how long in seconds but by editing the sleep time on line 9 you could make it go by minutes or hours.

    finally if a string is input it will crash numbers 1 - 9 are valid inputs example:
    123 by default would be one hundred and twenty three seconds
    Code:
    term.setTextColor(colors.lime) --optional adds color not compatible with regular computer!
    term.clear()
    term.setCursorPos(1,1)
    print("Timer running, please input how long:")
    rs.setOutput("back",true) --output needs to be inverted this is in case program crashes or the server restarts.
    x = read()
    while x ~= 0 do
    sleep(1) --this could be changed to 60 for a min or 3600 for an hour
    term.clear()
    term.setCursorPos(1,1)
    x = x - 1
    print(x)
    if
      x <= 0 then
      rs.setOutput("back",false)
      write("time is up, Turning off output")
      term.setCursorPos(1,3)
      print("press enter to reboot")
      reboot = read()
      os.reboot()
    end
    end
    

    Thanks i wrote this to help cut back on server cpu useage hope you guys like it.
     
  2. hsun324

    hsun324 Programmer, Gamer

    Joined:
    May 14, 2012
    Messages:
    362
    Likes Received:
    90
    Nice idea, but wouldn't a inverted state cell be a worthy solution, and one that doesn't cost 5 diamonds to boot. :)
     
  3. fxstriker

    fxstriker Good Bye skcraft.

    Joined:
    Jan 14, 2012
    Messages:
    259
    Likes Received:
    35
    Ummm.... yeah.... yeah it would ....

    my ways way more fun tho :( and more accurate and more configurable and if computers had the default recipe this would be so use full =P
     
  4. gknova61

    gknova61 Farbes Lover

    Joined:
    Mar 17, 2012
    Messages:
    1,238
    Likes Received:
    350
    If this program does crash/server restarts, it wouldn't know where it was as far as timings go. For example, you set this to run for an hour. 30min into the program the server restarts, and it needs the user to give it the time it's suppose to run again. Saving x to a file every so often and having the program check if the file exists (delete the file when the program is suppose to end) in the beginning and if it does, use that timing would help.
    A server restart would reset the state cell. Not good for if you wana keep loaded for extended periods of time.
     
  5. fxstriker

    fxstriker Good Bye skcraft.

    Joined:
    Jan 14, 2012
    Messages:
    259
    Likes Received:
    35
    i am not sure how it would react thru a restart a server crash could definitely stuff it up the program itself crashing is extremely unlikely but i am not ruling it out.
     
  6. fxstriker

    fxstriker Good Bye skcraft.

    Joined:
    Jan 14, 2012
    Messages:
    259
    Likes Received:
    35
    I think i can modify my code to save to a file ill update this later with v 2.0
     
  7. hsun324

    hsun324 Programmer, Gamer

    Joined:
    May 14, 2012
    Messages:
    362
    Likes Received:
    90
    If there is a server crash, then the chunk loader wouldn't load at all either. Adding in a resume wouldn't be of much use.
     
  8. fxstriker

    fxstriker Good Bye skcraft.

    Joined:
    Jan 14, 2012
    Messages:
    259
    Likes Received:
    35
    not entirely true at least know when it crashed so they can restart it