Open Computers

## **Synopsis**

Open Computers is a mod that, in short, adds computers, drones, and robots to the game. In this mod you will either need to know basic Lua 5.2 programming, or be open to learning Lua 5.2.

## **Disclaimer**

This guide is very similar to the guide at https://ocdoc.cil.li/

## **Getting Started**

### **Items needed:**

* Tier 1 Case
* Tier 1 Screen
* Keyboard
* Tier 1 Graphics Card
* Tier 1 CPU
* Two Tier 1 or 1.5 Memory Cards
* Disk Drive
* OpenOS
* Hard Drive
* Lua BIOS
* Power Supply (not included in mod)

## **Setting Up Your Computer**

To start off, place you case on the floor. After you have done that, go ahead and left click on the case and place the following items. Graphics card, CPU, Memory cards, Hard Drive, and Lua BIOS. Once you have done this, you may exit out of the case screen. Next, place a Screen next to the computer. Now place a keyboard in front of the screen. After that, place the disk drive on the other side on the Case and place the OpenOS inside of the disk drive. Now go ahead and connect a power supply cable to the bottom, top, or back of the computer case.

Your Computer is now Good To GO

## **Writing Programs**

So, you've built your first computer and wonder what to do with it?

Well, let's start with the good old, proven, beloved first program. You know which one. First off, let's switch to the `/tmp` folder, which is a small, writable file system each computer comes with. Remember, this gets *wiped on reboot*, so don't put anything valuable in here!

(Yes, that is copied from the wiki directly)

To switch to the `/tmp` folder, write in the console `cd /tmp`

Once you have done this, take a moment to think of a name for your very first open computers program!

Got one? Good! Now go ahead and type in the console: `edit yourprogramname.lua`

You should see a black screen with a blinking cursor and some text at the bottom pop up. This is the built-in text editor. To start with your first program, type: `print()`

This calls the 'print' function. What this function does is print a line of text to the screen when the program is run. Now, inside of the parentheses, type `"Hello World"` with the quotation marks included.

Go ahead and save your program by doing `ctrl + s`, and exit the program with `ctrl + w`. Once you have done this, type in the console `yourprogramname.lua` with nothing else in the console, and press enter. Your should see the words "Hello World" in the console.

## **Hard Drives**

Something to note about the `/tmp` folder, is that any programs you write in there will be cleared whenever you reboot the computer. So this section will be on how to use hard drives to store your program. When you put a hard drive into a computer it will be automatically mounted in the `/mnt` folder, named after the first letters of its address. While this may be enough for experimenting, you'll want more flexibility and comfort after a while. This tutorial will introduce the concept of labeling and mounting hard drives.

*Note*: all concepts in this tutorial also apply to floppy disks.

First, insert a fresh hard drive into a computer. You'll notice in the tooltip of the hard drive that it has been assigned an address (that shortened, alpha-numeric string). You don't have to remember that, it's just there for reference. Next, open the screen's GUI and type `df`. This program lists all present file systems and their current mount points. Among them you'll notice one that's only known by address (unlike the ROM and temporary file system). That should be the address you saw in the tooltip, earlier. What we want to do now, is to assign a name to our hard drive, so we don't have to reference it by address all the time. Run `label` to get the usage information of the labeling program. We'll use the `-a` option here, but you could also label it by providing the path to its default mount point in the `/mnt` folder. Run the program with the desired parameters, i.e. name the disk as you'd like. For most programs that need an address you can abbreviate the address, as long as it's still unique among the other components connected to the computer.

Once you've named your hard disk that name is also shown in the hard disk's tooltip. Run `df` again to verify the hard disk is now named.

We can now mount the hard drive while referring to it by name. Type `mount <label> <path>` to mount the hard drive with the specified label at the specified path. Hard drives can be mounted in multiple locations, so doing that will not invalidate the default mount in the `/mnt` folder.

Now, computers do not store any state across reboots. Meaning if you shut down or reboot your computer, it crashes or runs out of power, you'll have to mount your disk again after restarting. This can get annoying very quickly, so let's create an autorun script that mounts the disk for us when it is inserted. Every hard drive can have such an autorun script. It has to be named `autorun` or `autorun.lua` and must be in the root of the hard drives folder structure. This script is automatically executed when the disk is installed in a computer - unless you disable autorun via the the file system API.

Switch into your freshly mounted folder, and run `edit autorun.lua`.

Autorun scripts get the proxy of the storage medium they're on as their first parameter, so we can use Lua's varargs syntax to access it. We'll pass that to the `fs.mount()` function, which you find documented in the file system API.

Save that file and close it. After removing the hard disk from the computer and inserting it again, run `ls` and you should see the disk has been automatically mounted again.

## **Robots**

https://ocdoc.cil.li/api:robot (I will add more on this as I mess around with it)

For now, take a look at this tutorial: https://oc.cil.li/topic/446-black-hole-tutorial-02-robot-overview/

## **Components**

So what are components? If you have previous knowledge of programming, you can think of them as libraries. If you have no previous knowledge, you can think of them as files full of code that were previously written to interact with certain items and blocks.

Here is a list of all the different components

3D Printer - Abstract Bus - Access Point - Chunkloader - Computer - Crafting - Data Card - Database - Debug - Drone - Drive - EEPROM - Experience - Filesystem - Generator - Geolyzer - GPU - Hologram - Internet - Inventory Controller - Leash - Microcontroller - Modem - Motion Sensor - Navigation - Net Splitter - Piston - Redstone - Robot - Screen - Sign - Tank Controller - Tractor Beam - Transposer - Tunnel - World Sensor

As you can see, there is a lot. But what do they do? The only ones you really NEED are the computer and filesystem APIs. But again, what do they do? Well the computer API gives you access to all the cards in the computer case, and all the components attached. The filesystem API give you access to the file system allowing you to run shell commands from a file.