Tutorial/oc2 writing code: Difference between revisions

From OpenComputers: Rebooted
Jump to navigation Jump to search
imported>OCDoc Import
Imported from legacy OpenComputers documentation at ocdoc.cil.li
 
Clean up Markdown artifacts from DokuWiki migration
 
Line 3: Line 3:
So, you've [[Tutorial/oc1 basic computer|built your first computer]] and wonder what to do with it?
So, you've [[Tutorial/oc1 basic computer|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!
Well, let's start with the good old, proven, beloved first program. You know which one. First off, let's switch to the <code>/tmp</code> 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!


[[File:https://i.imgur.com/7YdcUbE.png|700px|https://i.imgur.com/7YdcUbE.png]]
[[File:https://i.imgur.com/7YdcUbE.png|700px|https://i.imgur.com/7YdcUbE.png]]


As shown in the image, type `edit <filename>`, where `filename` is the name of the file you wish to edit. The `.lua` extension is absolutely optional, I just like to keep it for syntax highlighting when opening the files in an external editor.
As shown in the image, type <code>edit &lt;filename&gt;</code>, where <code>filename</code> is the name of the file you wish to edit. The <code>.lua</code> extension is absolutely optional, I just like to keep it for syntax highlighting when opening the files in an external editor.


Once in the editor, start coding. In our case it's just the boring, uncreative-but-proven `print("Hello World!")`.
Once in the editor, start coding. In our case it's just the boring, uncreative-but-proven <code>print("Hello World!")</code>.


[[File:https://i.imgur.com/5F16EEV.png|700px|https://i.imgur.com/5F16EEV.png]]
[[File:https://i.imgur.com/5F16EEV.png|700px|https://i.imgur.com/5F16EEV.png]]


When you're done, press Ctrl+S to save, then press Ctrl+W to close the editor. If you list the contents of the `/tmp` folder now, you'll see the file has been created. Type its name and press enter to run it:
When you're done, press Ctrl+S to save, then press Ctrl+W to close the editor. If you list the contents of the <code>/tmp</code> folder now, you'll see the file has been created. Type its name and press enter to run it:


[[File:https://i.imgur.com/KiHVUMu.png|700px|https://i.imgur.com/KiHVUMu.png]]
[[File:https://i.imgur.com/KiHVUMu.png|700px|https://i.imgur.com/KiHVUMu.png]]


Notice that I didn't type the `.lua` extension when running it. The shell will look for files with that extension if it can't find the file with the exact name you specified.
Notice that I didn't type the <code>.lua</code> extension when running it. The shell will look for files with that extension if it can't find the file with the exact name you specified.


If want your programs to survive reboots, '''continue by reading on [[Tutorial/oc3 hard drives|how to use hard drives]]'''.
If want your programs to survive reboots, '''continue by reading on [[Tutorial/oc3 hard drives|how to use hard drives]]'''.
Line 24: Line 24:


{{:Tutorial/contents}}
{{:Tutorial/contents}}

Latest revision as of 20:28, 24 August 2026

OC Tutorial: Writing Code

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!

https://i.imgur.com/7YdcUbE.png

As shown in the image, type edit <filename>, where filename is the name of the file you wish to edit. The .lua extension is absolutely optional, I just like to keep it for syntax highlighting when opening the files in an external editor.

Once in the editor, start coding. In our case it's just the boring, uncreative-but-proven print("Hello World!").

https://i.imgur.com/5F16EEV.png

When you're done, press Ctrl+S to save, then press Ctrl+W to close the editor. If you list the contents of the /tmp folder now, you'll see the file has been created. Type its name and press enter to run it:

https://i.imgur.com/KiHVUMu.png

Notice that I didn't type the .lua extension when running it. The shell will look for files with that extension if it can't find the file with the exact name you specified.

If want your programs to survive reboots, continue by reading on how to use hard drives.

Contents

Tutorials
Mod Specific Basic Computer - Writing Code - Hard Drives - Autorun and Startup scripts
Modding Custom Architectures - IMC Messages
Programs OPPM - install
Others Custom Operating Systems