ComputerCraft

Automatic startup script

Write a startup.lua that runs automatically on every boot — no need to type anything after placing the computer.

What you will end up with

A CC:Tweaked computer that, on every boot, automatically clears the screen, prints a welcome message, and displays the current time. You can then extend the script to do anything you like — run programs, check inventories, or start a monitor display.

What you need

CC:Tweaked automatically runs a file called startup or startup.lua from the root of the computer's filesystem on every boot. This is the standard way to automate a computer without any extra configuration.

Step by step

  1. Place a Computer block and right-click it to open the terminal.
  2. Create the startup file using the built-in editor:
    edit startup.lua
  3. Type the following program into the editor:
    -- startup.lua -- Runs automatically on every boot term.clear() term.setCursorPos(1, 1) print("=== AIVONI MC ===") print("") print("Server: mc.aivoni.eu") print("Time: " .. textutils.formatTime(os.time(), true)) print("") print("Computer ready.")
  4. Save and exit: press Ctrl, select Save, then press Ctrl again and select Exit.
  5. Reboot the computer to test:
    reboot
    The script should run immediately on startup.

How it works

When CC:Tweaked boots a computer it looks for a file named startup or startup.lua in the root directory and executes it automatically. No special registration is needed — just the file name.

The script above uses a few standard CC:Tweaked APIs:

Running another program from startup

If you want the startup script to launch another program (for example your monitor display), use shell.run() at the end of startup.lua:

-- At the end of startup.lua, launch another program: shell.run("my_program")
shell.run() runs the program and waits for it to finish before continuing. If your program runs in an infinite loop, the startup script will stay in that loop — which is usually exactly what you want for a permanent display or monitor program.

Editing startup after a reboot

If the startup script runs an infinite loop, you can interrupt it by holding Ctrl + T for about two seconds. This terminates the running program and returns you to the shell, where you can edit the file again.

Full example — startup with monitor launch

-- startup.lua — boots into the monitor display program term.clear() term.setCursorPos(1, 1) print("Booting AIVONI monitor...") os.sleep(0.5) shell.run("monitor_display")