Robot BIOS program for Minecraft OpenComputers mod.
OC robots are very difficult to assemble and program. This program for the BIOS will help to use robots as "users" and in many other ways.
Assemble the robot in the minimum configuration:
- Case
- CPU
- RAM
If you play Enigmatica 2: Expert - Extended, modpack have predefined recipe of EEPROM.
Just find it in JEI and craft. It would have colored shining.
If you crafted it, you can skip next step Write program on EEPROM
.
You need a working OC computer to write the BIOS. See this tutorial to assemble your first computer.
wget https://gist.githubusercontent.com/Krutoy242/db63637d605c2c247bc95e939c7f7ddd/raw/lostuser.min.lua
- To write on existing EEPROM run:
flash -q lostuser.min.lua LostUser
Take EEPROM from computer case and merge with robot.
Robot programmed by renaming it. You must rename Robot on or with (from Integrated Dynamics item).
Name your Robot \3
, place on ground, turn on, and see how its clicking blocks in front.
If you don't want to learn Lua and you need the robot to right/left click, a few simple names for the robot and the result:
\3z
The robot will right click on the block on the front each second./3z
The robot will swing with a sword or break the block in front of it.
-
Each symbol means command
Progran run from left to right. Each symbol executed and return its result forward. For example:
\3z
- This program would callrobot.use(3)
then callrobot.move(3)
-
Some actions have parameters
Parameters can be any value.
All 1-digit numbers parsed as numbers. Usually its sides.|0|1m3
- Place blocks under robot (|
is alias forrobot.place
), then over the robot, then move forward. -
Commands return values
This values can be used for other functions as parameters.
^(#1)
- Select slot equal number of items in first slot. Robot must haveProgram here run first command
^
(robot.select
), but it needs a param, so it try to get param from next command.#
is alias forrobot.count
, so its return number used as param for^
command.Notice that without the brackets
^#1
, therobot.select
function would get therobot.count
function as a parameter, which would cause an error. -
Constants
There is few constants:
n
- number of inventory slots. Equal to executingrobot.inventorySize()
i
- if you are insidefor i
loop, or was in it, return lasti
*
- alias fornil
#n
- Select last slot of robot, if it have inventory upgrade.
Operators is hardcoded symbols that control program flow.
All parameters have default values. You can use defaul values by calling operators with nil
instead parameters.
Symbol | Params | Description | Example |
---|---|---|---|
- |
value=true |
Write value into variable with symbol right after - . |
-a5 - writes 5 into variable with name a . |
~ |
program='' |
Define a symbol right after ~ as alias with code in parameter program . This code would run when alias symbol occur. |
~M'm1' MMM - define symbol M as program m1 (means robot.move(1) ), and then execute it 3 times. |
? |
condition=false onTruthy='' onFalthy='' |
if condition then return onTruthy() else return onFalthy() end |
?M"R"'L' - If succesfully moved forward, turn right, or turn left otherwise.?{<#5>>0}'^i'* - select slot 5 if its non-empty. Do nothing otherwise. |
! |
program='' from='1' to='maxinteger' |
for i=from ,to ,1 do program() endBreak loop when program() return truthy value |
!"?{<#i>>0}'^i'*"1n - Select first non-empty slot. |
Symbol | Description | Example |
---|---|---|
' " ` | Takes all text until next quote and return as string. | -a"one'two'" - writes string one'two' into variable a |
( code) |
Run code inside parenthesis and return its value.(¹) Note that capture is not recursive. (a(b)) would capture (a(b) |
z(#1) - sleeps for number of seconds equal to number of items in first slot. |
{ lua} |
Return as lua evaluated expression.(²)(³) | t{true} - turn right.^{12} - select 12th slot.{proxy'piston'.push}3 - push block in front (if piston upgrade installed) |
[ pointer] |
Return pointer to globals. Can use shortands. First letter is mandatory, other can content any symbols between. | [cpr] or [computer] - return global variable computer [cpr.bep] - return computer.beep |
¹ : Only last result would be returned.
-a1 -b2 ^(ab)
- Would select second slot.
² : You can use < >
inside lua code to execute program between < >
as commands.
-a{not <a>}
- Negate variablea
.
³ : There is some predefined globals:
proxy
r = proxy"robot"
ic = proxy"y_c"
There is many predefined symbols. See them at the beginning of source file.
Robots without screen and GPU cant show messages. So, there is predefined function e
that could throw an error that would be visible by right-clicking .
e[r.cT]
- Error withrobot.compareFluidTo
documentation.
If you want a deeper level of debugging, load the program on a robot with a complete package - , etc.
Download program on robot:
wget https://gist.githubusercontent.com/Krutoy242/db63637d605c2c247bc95e939c7f7ddd/raw/d63a80a7ec6393bad8a44ef6803de9895eec3d43/lostuser.lua
The program can accept 2 commands
- The program text to execute (instead of the robot's name)
- Logging output level [1-3]
- Programs and subprograms only
- All commands
- Include initialization commands in the debug
Since the robot screen is very small, I suggest redirecting the output to a file.
Example:
Run this from shell. Robot would move forward and then stop program.
lostuser.lua "MX" 2 > out
Rich debug info would be output into out
file:
PROGRAM "MX" {
ALIAS M == "m3"
PROGRAM "m3" {
VAR m == "function(direction:number):boolean -- Move in the specified direction."
} return true
ALIAS X == "[os.exit]*"
PROGRAM "[os.exit]*" {
api: os.exit os.exit
We would use this robot to breeding Industrial Craft 2 crops.
To do this, you need to plant the seeds in a checker order, and put cross sticks between them. Also, the robot has to run along the bed and right-click Weeding Trowel to pick up the weeds.
In this example, the robot runs a complex program: ?(y0)'E9nS18''^9/0s18|0'Z
.
This program:
- Tosses items from slots 9-16 down
- Picks up items in slots 1-8 from top
- Moves in a zig-zag pattern, breaks the block underneath and puts a new one
- Gist with source code and readme
- Modpack this robot was programmed for: Enigmatica 2: Expert - Extended