The second post is for my filebrowser system (CookieSystem).
The third post is for project world eater and related things.
CookieCannon
Spoiler
Four cannons controlled by a single computer and loaded with two chests. Each cannon also has a separate computer but those need no interaction and all got exactly the same program running. The main computer has a little UI showing each cannon's status (the amount of TNT in the cannon's chest, if there is a cannon in a deployer (D or .), if the booster charges are set (B or .), if the ammo is deployed (X or _), and how much ammo there is in the ammo deployer.Commands are
select (cannon) – selects a cannon, all other commands affect the selected cannon
sendbooster (amount) – sends tnt to the booster chest
sendammo (amount) – sends tnt to the ammo deployer
deploy (1-7) – sends a tnt to one of the deployers
deploy ammo – activates the ammo deployer (the one at the end of each cannon)
deploy booster – activates all deployers
Chicken Factory
Spoiler
(copy of youtube description)My Chicken Farm/Factory. Made with Redpower 2, Computercraft and a tiny bit of IC2 (at the end). It got two computers as a lock for both doors, one master control terminal in the control room (used for misc. commands and needed to activate the others) and five computers that regulate the resources (counting + retrieving). The farm itself contain a regular chicken pen and a second one with an incinerator hooked to it, in case some chickens die and leave raw meat behind there is a cooker that automatically processes raw meat.
Some notes:
-The feather counter actually works, it looks a bit weird because it had 7 before I took out 4 and shows up with 6 after I check again. But when I open the chest later in the video you see it has 6 feathers.
-The incinerator not killing all chickens is a good thing, because having some chickens left behind is good for causing chicken decompression. Without it all the chickens will stay on one spot without moving until something bumps into it.
Here's the pastebin with the code of the self destruct countdown http://pastebin.com/hWcuT6wc
Here's the world save + configs + some instructions. You need to have some knowledge of installing mods to do this.
http://www.mediafire...7g3c9ko2ts9bq3e
E-mails (and virus)
Spoiler
A bit outdated now we got rednet and stuff, but this is one of the first networking programs (at least that use bundled cables). It goes at a rate of 2000 chars/minute using five bundled cables (at half potential). It converted characters in numbers and then sends those trough the cables, the other side then converts them back. It's pretty stable, especially v3 , and only started to get scramble when sending very large files.Send code V3
Spoiler
if redstone.getInput("back")
then
print("Line already in use, try later.")
else
string = ""
file = io.open("netpackage", "r")
strpart = {}
string = ""
strpart = {}
strpart[1] = ""
i=2
while true do
line = file:read()
if line == nil then break end
strpart[i] = line
i=i+1
end
file:close()
for i=1, #strpart do
string = (string..strpart[i].."nxt".."ln")
end
firstchar = {}
firstnum = {}
secondchar = {}
secondnum = {}
thirdchar = {}
thirdnum = {}
fourthchar = {}
fourthnum = {}
fifthchar = {}
fifthnum = {}
n=0
repeat
n=n+1
if (string.len(string) >= 5)
then
firstchar[n] = string.sub(string,1,1)
firstnumt = string.byte(firstchar[n])
firstnum[n] = (firstnumt + 32768)
secondchar[n] = string.sub(string,2,2)
secondnum[n] = string.byte(secondchar[n])
thirdchar[n] = string.sub(string,3,3)
thirdnum[n] = string.byte(thirdchar[n])
fourthchar[n] = string.sub(string,4,4)
fourthnum[n] = string.byte(fourthchar[n])
fifthchar[n] = string.sub(string,5,5)
fifthnum[n] = string.byte(fifthchar[n])
string = string.sub(string,6)
else
firstchar[n] = string.sub(string,1,1)
firstnumt = string.byte(firstchar[n])
firstnum[n] = (firstnumt + 32768)
string = string.sub(string,2)
secondnum[n] = 0
thirdnum[n] = 0
fourthnum[n] = 0
fifthnum[n] = 0
end
until string.len(string) == 0
redstone.setBundledOutput("back", 32768)
sleep(0.1)
m=0
repeat
m=m+1
redstone.setBundledOutput("back", firstnum[m])
redstone.setBundledOutput("top", secondnum[m])
redstone.setBundledOutput("bottom", thirdnum[m])
redstone.setBundledOutput("left", fourthnum[m])
redstone.setBundledOutput("right", fifthnum[m])
sleep(0.12)
until m == n
redstone.setBundledOutput("top", 0)
redstone.setBundledOutput("bottom", 0)
redstone.setBundledOutput("back", 0)
redstone.setBundledOutput("left", 0)
redstone.setBundledOutput("right", 0)
end
Receive code V3
Spoiler
string = ""
newchar = ""
finished = false
ended = false
while true do
event = os.pullEvent()
if event == "redstone" then
if redstone.getBundledInput("back") == 32768
then
sleep(0.15)
break
end
end
end
numone = {}
numtwo = {}
numthree = {}
numfour = {}
numfive = {}
n=0
repeat
n=n+1
numonet = redstone.getBundledInput("back")
numone[n] = (numonet - 32768)
numtwo[n] = redstone.getBundledInput("top")
numthree[n] = redstone.getBundledInput("bottom")
numfour[n] = redstone.getBundledInput("left")
numfive[n] = redstone.getBundledInput("right")
sleep(0.12)
until redstone.getBundledInput("back") < 32768
charone = {}
chartwo = {}
charthree = {}
charfour = {}
charfive = {}
m=0
repeat
m=m+1
charone[m] = string.char(numone[m])
chartwo[m] = string.char(numtwo[m])
charthree[m] = string.char(numthree[m])
charfour[m] = string.char(numfour[m])
charfive[m] = string.char(numfive[m])
string = (string..charone[m]..chartwo[m]..charthree[m]..charfour[m]..charfive[m])
until m == n
string = string.gsub(string, ("nxt".."ln") , "n")
string = string.sub(string, 1, -6)
file = io.open("netpackage", "w")
file:write(string)
file:close()
To use this you need to connect your computers to a big cable (5 bundled ones) and have each bundle only connected to one side.
So one bundle is connected to all your computers' back sides, the second to all the tops, third to all the bottoms, fourth to all the lefts and fifth to all the rights. The front is unused.
setup:
Spoiler
Connect 4 (multiplayer)
Spoiler
Two computer multiplayer, using a disk in the middle. It automatically detects for four in a rows and all the other stuff you expect from a four in a row computer game.code:
Spoiler
repeat
print("Which player are you? (1 or 2)")
compplayer = read()
compplayer = compplayer+1-1
if compplayer == 1 then otherplayer = 2 end
if compplayer == 2 then otherplayer = 1 end
until compplayer == 1 or compplayer == 2
player = 2
onarow = 1
fiar = false
nmds = 0
nmdg = 0
lmc = 0
lmr = 0
field = {}
for i=1,7 do
field[i] = {}
for j=1,6 do
field[i][j] = 0
end
end
for s=1, 6 do
if s == 1 then sidecheck = fs.exists("disk/connectmp")
else sidecheck = fs.exists("disk"..s.."/connectmp")
end
if sidecheck == true
then
if s == 1 then path = "disk/"
else
path = ("disk"..s.."/")
end
end
end
file = fs.open(path.."moveplayerone", "w")
file:close()
file = fs.open(path.."moveplayertwo", "w")
file:close()
function printfield()
term.clear()
term.setCursorPos(1,1)
for i=1,6 do
for j=1,7 do
write(field[j][i].." ")
end
print()
end
end
function hasemptyspot(column)
check = 1
for n=1, 6 do
check = check * field[column][n]
end
if check == 0
then
return true
end
end
function setpiece(column)
n = 6
column = column + 1 - 1
while true do
if field[column][n] == 0 then break end
n=n-1
end
field[column][n] = player
lmc = column
lmr = n
end
function changeplayer()
if player == 2
then player = 1
else
if player == 1 then player = 2 end
end
end
function cfwhelp(n,i,j)
lmch = lmc + n*i
lmrh = lmr + n*j
if i ~= 0 or j ~= 0 then
if lmch >= 1 and lmch <= 7 and lmrh >= 1 and lmrh <= 6
then
if field[lmch][lmrh] == player
then
onarow = onarow + 1
inrow = true
if onarow >= 4 then fiar = true end
end
end end
end
function checkforwin()
for i=-1, 1 do
for j=-1, 1 do
onarow = 1
for n=1, 3 do
inrow = false
cfwhelp(n,i,j)
if inrow == false then break end
end
for n=-1, -3, -1 do
inrow = false
cfwhelp(n,i,j)
if inrow == false then break end
end
end
end
if fiar
then
return true
end
end
function sendmove(column)
if compplayer == 1
then
file = io.open(path.."moveplayerone", "w")
file:write(column)
file:close()
end
if compplayer == 2
then
file = io.open(path.."moveplayertwo", "w")
file:write(column)
file:close()
end
redstone.setOutput("back", true)
sleep(0.15)
redstone.setOutput("back", false)
end
function getmove()
print()
print()
print("Waiting for other player. Press Q to exit if he takes too long.")
while true do
event,argument = os.pullEvent()
if event == "char" and argument == "q" then os.reboot() end
if event == "redstone" and redstone.getInput("back")
then
if otherplayer == 1
then
file = io.open(path.."moveplayerone", "r")
column = file:read()
file:close()
break
end
if otherplayer == 2
then
file = io.open(path.."moveplayertwo", "r")
column = file:read()
file:close()
break
end
end
end
end
function doturn()
pieceset = false
repeat
print("Turn: "..turn..". Player "..player.."'s turn. Choose a column.")
column = read()
if column == "quit" then os.shutdown() end
if column ~= "1" and column ~= "2" and column ~= "3" and column ~= "4" and column ~= "5" and column ~= "6" and column ~= "7"
then
print("Invalid column.")
else
column = column + 1 - 1
if hasemptyspot(column)
then
setpiece(column)
pieceset = true
else
print("Column is already full.")
end
end
until pieceset
end
turn = 0
printfield()
repeat
changeplayer()
if player == compplayer
then
turn = turn+1
doturn()
sendmove(column)
printfield()
print("You've set a new piece in column "..lmc..".")
end
if player == otherplayer
then
getmove()
setpiece(column)
printfield()
print("Player "..player.." has set a new piece in column "..lmc..".")
end
until checkforwin()
print("Player "..player.." has a four in a row and wins!")
fs.delete( (path.."moveplayerone") )
fs.delete( (path.."moveplayertwo") )
Persistent Variables (api)
Spoiler
A standalone api that saves your variables and allows you to change/read them later on. It is designed to work together with CookieSystem, which is why the default path is "/CookieSystem/CS System/pervar/", but that can be changed at the top of the program.Currently there are four functions:
pervarcreate(variablename) – creates a new (empty) variable. but only if it doesn't exist already.
pervardelete(variablename) – deletes an existing variable.
pervarchange(variablename, newvalue) – changes the variable to newvalue
pervarread(variablename) – reads the variable
so pervarcreate("rawr") would create it.
Then you can use pervarchange("rawr", 30) to set it to 30.
print(pervarread("rawr")) will give 30.
pervardelete("rawr") will then delete the variable.
The code:
Spoiler
pervarpath = "/pervar/"
if fs.exists(pervarpath) == false
then fs.makeDir(pervarpath) end
function pervarcreate(pervarname)
pervarfile = io.open(pervarpath..pervarname..".txt", "r")
if pervarfile
then
pervarfile:close()
return "Variable already exists"
else
pervarfile = io.open(pervarpath..pervarname..".txt","w")
end
end
function pervardelete(pervarname)
pervarfile = io.open(pervarpath..pervarname..".txt", "r")
if pervarfile
then
pervarfile:close()
fs.delete(pervarpath..pervarname..".txt")
else
return "Variable doesn't exist"
end
end
function pervarchange(pervarname, newvalue)
pervarfile = io.open(pervarpath..pervarname..".txt", "r")
if pervarfile
then
pervarfile:close()
pervarfile = io.open(pervarpath..pervarname..".txt","w")
pervarfile:write(newvalue)
pervarfile:close()
else
return "Variable doesn't exist"
end
end
function pervarread(pervarname)
pervarfile = io.open(pervarpath..pervarname..".txt", "r")
if pervarfile
then
pervarcontent = pervarfile:read()
pervarfile:close()
return pervarcontent
else
return "Variable doesn't exist"
end
end
To use it in your programs you can either paste this code on top of your program or put this code in a separate program and add the line "shell.run("path+name")" to the top of your code.
The Turtle Factory
Spoiler
[media]http://www.youtube.com/watch?v=rqKBC-bNiVA[/media]You throw the items in the bucket (or have a turtle do it!) and push the button at the end of the production line and get a ready to use pre-programmed turtle! It automatically sorts all materials you throw in it, with a build in incinerator to dispose of what you don't need, then it processes the raw materials until it eventually becomes a wireless mining turtle!
Some (slightly outdated) images to explain what each part does:
Spoiler
Pathfinding and Waypoints (using coordinates)
Spoiler
outdated video: (it's easier to use now, but the core still works the same)[media]http://www.youtube.com/watch?v=kF_EMyUAfJo&feature=player_embedded[/media]
A navigation program based on coordinates, using my persistent variables api I made it possible for the turtle to remember where he is, so you just give it his coords when you set him up and you're good to go. It automatically follows coords in a waypoints text file (using the format x,y,z so without any brackets). It also has some basic block avoidance (see video), though it will still get stuck sometimes, especially against larger or complex things, but it's designed for air travel where there aren't many obstacles usually.
Skynetapi
Spoiler
Allows you to send long range messages via a network of special wireless repeaters. Note: You have to open the rednet ports separatelyFunctions are
skynetrepeater() – Use this to make a turtle/computer act as a repeater.
skynetsendmessage(message, targetid) – sends the string message to the computer with id targetid (it will only arrive if both computers are connected to the same network).
skynetreceivemessage() – Waits for a skynet message and returns it.
skyneteventmessage() – This one works more like an os.pullEvent() with an extra event named "skynet" (which has the first parameter as message), so that you can wait for a skynet message or a key press or anything else.
Spoiler
--Repeater
function messageisnew()
for ticn = 1, ticmemcounter do
if timeandid == ticmem[ticn]
then
return false
end
end
return true
end
function addtoticmem(newti)
ticmemcounter = ticmemcounter + 1
ticmem[ticmemcounter] = newti
end
function resetticmem()
ticmemcounter = 0
ticmem = {}
os.setAlarm(0)
end
function skynetrepeater()
resetticmem()
while true do
event, id, message = os.pullEvent()
if event == "rednet_message"
then
if string.sub(message,1,8) == "[skynet]"
then
timeandid = string.sub(message,9,21) -- [TTTTTTIIIII]
if messageisnew()
then
addtoticmem(timeandid)
rednet.broadcast(message)
end
end
elseif event == "alarm"
then
resetticmem()
end
end
end
--Sender
function getticode()
time = os.time()
for n=1, 6 do
if string.len(time) < n
then time = time.."0"
end
end
id = os.getComputerID()
for n=1, 5 do
if string.len(id) < n
then id = "0"..id
end
end
timeandidcode = ("["..time..id.."]")
return timeandidcode
end
function gettargetid(targetidf)
targetidf = tostring(targetidf)
for tidlenc=1, 4 do
if string.len(targetidf) == tidlenc
then
targetidf = ("0"..targetidf)
end
end
targetidf = "["..targetidf.."]"
return targetidf
end
function skynetsendmessage(message, targetid)
if message and targetid then
rednet.broadcast("[skynet]"..getticode()..gettargetid(targetid)..message) --[skynet][TTTTTTIIIII][IIIII]
end
end
--Receiver
function istargetid()
targetid = tonumber(string.sub(skynettags,23,27))
if targetid == os.getComputerID()
then
return true
else
return false
end
end
function skynetreceivemessage()
while true do
event, id, message = os.pullEvent()
if event == "rednet_message"
then
skynettags = string.sub(message,1,28)
if string.sub(skynettags,1,8) == "[skynet]" then
if istargetid() then
message = string.sub(message,29)
return message
end
end
end
end
end
function skyneteventmessage()
while true do
event, id, message = os.pullEvent()
if event == "rednet_message"
then
skynettags = string.sub(message,1,28)
if string.sub(skynettags,1,8) == "[skynet]" then
if istargetid() then
message = string.sub(message,29)
return "skynet", message
end
end
else
return event, id, message
end
end
end
IRC
Spoiler
A basic chat program that uses the skynetapi. First make sure you're connected to a skynet, then make sure there is a computer running the IRCserver program and get its ID. Then you have to open the IRCclient program on your own computer and configure the rednet modem side and server id at the top.commands are
/quit – be sure to use this when you stop. It causes you to logout so the server won't send messages to your computer anymore.
/name – Name yourself.
If you don't type a "/" at the start it will send the message to the IRC server and broadcast it to all connected people.
IRCserver
Spoiler
rednet.open("top") -- Be sure to adjust this if necessary!!
shell.run("skynetapi")
function broadcastmessage()
for bcmc = 1, #idlist do
targetid = idlist[bcmc]
skynetsendmessage("[IRC]"..message, targetid)
end
end
function addidtolist()
newid = tonumber(string.sub(message,1,5))
idlist[#idlist+1] = newid
end
function removeidfromlist()
removeid = tonumber(string.sub(message,1,5))
for rifln=1, #idlist do
if removeid == tonumber(idlist[rifln])
then
for rifln2 = rifln, #idlist-1 do
idlist[rifln2] = idlist[rifln2+1]
end
idlist[#idlist] = nil
break
end
end
end
idlist = {}
while true do
newmessage = skynetreceivemessage()
type = string.sub(newmessage,1,5)
message = string.sub(newmessage,6)
if type == "[NID]" then addidtolist()
elseif type == "[MSG]" then broadcastmessage()
elseif type == "[RID]" then removeidfromlist()
end
print(#idlist)
end
IRCclient
Spoiler
rednet.open("top") --Be sure to adjust this if necessary!!
IRCserverid = 51 --Be sure to adjust this if necessary!!
shell.run("skynetapi")
function formatnumbertostring(fnumber, flength)
fnumber = tostring(fnumber)
if string.len(tostring(fnumber)) > flength then return false end
if string.len(tostring(fnumber)) == flength then return tostring(fnumber) end
if string.sub(fnumber,1,1) == "-"
then
fnumber = string.sub(fnumber,2)
for formatnumbern=1, (flength-2) do
if string.len(fnumber) == formatnumbern
then fnumber = ("0"..fnumber)
end
end
fnumber = ("-"..fnumber)
else
for formatnumbern=1, flength-1 do
if string.len(fnumber) == formatnumbern
then fnumber = ("0"..fnumber)
end
end
end
return fnumber
end
function login()
message = "[NID]"..formatnumbertostring(os.getComputerID(), 5)
skynetsendmessage(message, IRCserverid)
end
function logout()
message = "[RID]"..formatnumbertostring(os.getComputerID(), 5)
skynetsendmessage(message, IRCserverid)
end
function sendmessage()
userid = os.getComputerID()
if username then userid = username end
message = ("[MSG]"..userid..": "..typeline)
skynetsendmessage(message, IRCserverid)
end
function printnewline()
message = string.sub(par1,6)
print(message)
end
function executeline()
if string.sub(typeline,1,1) == "/"
then
if string.sub(typeline,2,5) == "quit" then logout() os.shutdown()
elseif string.sub(typeline,2,5) == "name" then username = string.sub(typeline,7)
end
else
sendmessage()
end
typeline = ""
end
function updatetop()
previousx, previousy = term.getCursorPos()
term.setCursorPos(1,1)
term.clearLine()
print(">"..typeline)
print("--------------------")
term.setCursorPos(previousx, previousy)
end
function ircclient()
maxx, maxy = term.getSize()
while true do
event, par1 = skyneteventmessage()
if event == "skynet" and string.sub(par1,1,5) == "[IRC]" then printnewline() sleep(0.1)
elseif event == "key" and par1 == 14 and string.len(typeline) > 0 then typeline = string.sub(typeline,1, string.len(typeline)-1) updatetop()
elseif event == "key" and par1 == 28 and string.len(typeline) > 0 then executeline() updatetop()
end
if event == "char" and string.len(typeline) < maxx
then
typeline = (typeline..par1)
updatetop()
end
end
end
term.clear()
term.setCursorPos(1,3)
typeline = ""
login()
updatetop()
ircclient()
CookieTV
Spoiler
[media]http://www.youtube.com/watch?v=aQvWje4npHU&feature=plcp&context=C47c2e9bVDvjVQa1PpcFMLuMMbyF2FHkrqbZ34N3R4vZuxlLrx454%3D[/media]A television in Minecraft, using Redpower 2, Computercraft and of course the Laser mod. It has 15*10 7 colour pixels, controlled by 6 computers. Another main computer is needed to send the image codes via rednet. That computer also has an image creation program, allowing images to easily be made with arrow and number keys in a special UI, unfortunately it can't load images yet. The images are saved as 450 byte binary files, each segment of 75 0/1's has another 5 segments with a length of 15 (one per row), which got the RGB on/off states for each pixel.
The smily image is this:
111001110110111111110001111111111110110111111111111111111111111111111111111
111111111111111111111111111111111110110111111111110001111111111110110110111
111110110110111111110001110111111111110111111111111111111111111111111111111
111111111111111111111111111111111111110111111111110110110111111110110110111
111110110001111111111001110111111111110110111111111111111111111111111111111
111111111111111111111111111111111111110110111111111001110111111110110110111
A big chunk of 1's means a white area, since white is 111 (red on, green on and blue on).The Code:
Pixelcontroler: Each one gets an unique ID from 1-6. The bottom ones get an uneven number and the top ones an even one. From right to left it goes 1/2 - 3/4 - 5/6.
Spoiler
TVCID = 1
rednet.open("front")
side = {"top", "right", "back", "left", "bottom"}
function receivecode()
while true do
event, id, message = os.pullEvent()
if event == "rednet_message" then
if string.sub(message,1,4) == "[TV]"
then
message = string.sub(message,5)
break
end
end
end
end
function filtercode()
filteredcode = string.sub(message, 1+(TVCID-1)*75, TVCID*75)
rowsegment = {}
for n=1, 5 do
rowsegment[n] = string.sub(filteredcode,1,15)
filteredcode = string.sub(filteredcode,16)
end
end
function filtersegment(rowsegment)
pixelsegment = {}
for n=1,5 do
pixelsegment[n] = string.sub(rowsegment,1,3)
rowsegment = string.sub(rowsegment,4)
end
end
function readrow(row)
filtersegment(row)
red = {}
green = {}
blue = {}
for n=1, 5 do
red[n] = tonumber(string.sub(pixelsegment[n],1,1))
green[n] = tonumber(string.sub(pixelsegment[n],2,2))
blue[n] = tonumber(string.sub(pixelsegment[n],3,3))
end
outputnumber = 0
for n=1, 5 do
outputnumber = outputnumber + red[n]*2^(3*(n-1)) + green[n]*2^(3*(n-1)+1) + blue[n]*2^(3*(n-1)+2)
end
end
function readcode()
for rownumber=1, 5 do
readrow(rowsegment[rownumber])
rs.setBundledOutput(side[rownumber], outputnumber)
end
end
while true do
receivecode()
filtercode()
readcode()
end
showimage:
Used by typing "showimage " like "image smily".
Spoiler
rednet.open("back")
tArgs = {...}
imagename = tArgs[1]
function getimagecode()
file = io.open(imagename, "r")
if file then
imagecode = file:read()
file:close()
else print("Select a valid image") end
end
function sendimagecode()
rednet.broadcast("[TV]"..imagecode)
end
getimagecode()
sendimagecode()
Createimage
To use you have to run it and first type an image name, it will be saved as this. Use the arrow keys to move the selected pixel (shown by the *'s on the borders of the image 'preview') and a number between 0-6 to change the colour. Press S and type yes to save, and Q to quit.
Spoiler
function ini()
term.clear()
term.setCursorPos(1,1)
print("imagename:")
imagename = read()
curselpxlX = 1
curselpxlY = 1
end
function convbintonum(bin)
if bin == "111" then num = 0
elseif bin == "100" then num = 1
elseif bin == "010" then num = 2
elseif bin == "001" then num = 3
elseif bin == "110" then num = 4
elseif bin == "011" then num = 5
elseif bin == "101" then num = 6
end
return num
end
function loadimage()
file = io.open(imagename, "r")
imagecodestring = file:read()
file:close()
end
function convnumtobinstring(num)
if num == 0 then bin = "111"
elseif num == 1 then bin = "100"
elseif num == 2 then bin = "010"
elseif num == 3 then bin = "001"
elseif num == 4 then bin = "110"
elseif num == 5 then bin = "011"
elseif num == 6 then bin = "101"
end
return bin
end
function getimagecode()
imagecodestring = ""
for n=1, 6 do
if n == 1 or n == 2 then startx = 3 elseif n == 3 or n == 4 then startx = 2 else startx = 1 end
if n == 1 or n == 3 or n == 5 then starty = 6 else starty = 1 end
for p=0, 4 do
for q=0, 4 do
imagecodestring = imagecodestring..convnumtobinstring(image[startx+3*q][starty+p])
end
end
end
return imagecodestring
end
function printfield()
term.setCursorPos(1,1)
term.clearLine()
print(imagename)
term.clearLine()
write("+")
write(string.rep("-", 15))
print("+")
for i=1, 10 do
term.clearLine()
write("|")
for j=1, 15 do
write(image[j][i])
end
write("|")
print()
end
term.clearLine()
write("+")
write(string.rep("-", 15))
print("+")
print("Move around with the arrow keys, change colour by pressing 0-6.")
print("0: white 1: red 2: green 3: blue 4: yellow 5: cyan 6: purple")
end
function newimage()
image = {}
for j=1, 15 do
image[j] = {}
for i=1, 10 do
image[j][i] = 0
end
end
end
function showselectedpixel()
term.setCursorPos(curselpxlX+1, 2)
write("*")
term.setCursorPos(curselpxlX+1, 13)
write("*")
term.setCursorPos(1, curselpxlY+2)
write("*")
term.setCursorPos(17, curselpxlY+2)
write("*")
end
function move()
if key == 200 then
if curselpxlY > 1 then curselpxlY = curselpxlY - 1 end
elseif key == 208 then
if curselpxlY < 10 then curselpxlY = curselpxlY + 1 end
elseif key == 203 then
if curselpxlX > 1 then curselpxlX = curselpxlX - 1 end
elseif key == 205 then
if curselpxlX < 15 then curselpxlX = curselpxlX + 1 end
end
end
function quit()
term.setCursorPos(1,13)
term.clearLine()
term.setCursorPos(1,15)
term.clearLine()
term.setCursorPos(1,16)
term.clearLine()
term.setCursorPos(1,17)
term.clearLine()
term.setCursorPos(1,14)
term.clearLine()
print("Do you want to quit?")
answer = read()
if answer == "yes" then
print("Ending...")
sleep(1)
term.clear()
term.setCursorPos(1,1)
end
end
function save()
term.setCursorPos(1,13)
term.clearLine()
term.setCursorPos(1,15)
term.clearLine()
term.setCursorPos(1,16)
term.clearLine()
term.setCursorPos(1,17)
term.clearLine()
term.setCursorPos(1,14)
term.clearLine()
print("Do you want to save?")
answer = read()
if answer == "yes" then
file = io.open(imagename, "w")
file:write(getimagecode())
file:close()
end
end
function moveandedit()
while true do
event, arg = os.pullEvent()
if event == "key"
then
key = arg
if key == 200 or key == 203 or key == 205 or key == 208 then
move()
end
elseif event == "char"
then
char = arg
if char == "0" or char == "1" or char == "2" or char == "3" or char == "4" or char == "5" or char == "6" then
char = tonumber(char)
image[curselpxlX][curselpxlY] = char
elseif char == "q" then quit() if answer == "yes" then break end
elseif char == "s" then save()
end
end
printfield()
showselectedpixel()
end
end
ini()
newimage()
printfield()
showselectedpixel()
moveandedit()
It's impossible to make the emptyimage file while it is very handy for shutting down the TV. It's a simple file though, just 450 zeros. Like this
Spoiler
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Frame Engine Factory
Spoiler
This Turtle makes an entire compact 6 directional frame engine all by itself (after you build the construction area and run the program). The video is on 4x speed for the most part, the turtle takes about 10-15 minutes building the whole thing. It's based on the frame engine I made that can be seen in my nuke missile and engine tutorial video, with some minor changes. Power input and controls are supposed to be external.[media]http://www.youtube.com/watch?v=4yROBWMLDW8[/media]
Code:
Spoiler
function dropslotxto16(minslot)
for currentdropslot = minslot, 16 do
turtle.select(currentdropslot)
turtle.dropDown()
end
turtle.select(1)
end
function getamountfrominventory(amountneeded)
turtle.suckDown()
repeat
amountinturtle = turtle.getItemCount(1)
if amountinturtle < amountneeded then
turtle.suckDown()
dropslotxto16(2)
end
until
amountinturtle >= amountneeded
if amountinturtle > amountneeded then
turtle.dropDown(amountinturtle-amountneeded)
end
end
function getframes(amountneeded)
turtle.up()
turtle.back()
turtle.back()
getamountfrominventory(amountneeded)
turtle.forward()
turtle.forward()
turtle.down()
end
function getpanels(amountneeded)
turtle.up()
turtle.back()
turtle.back()
turtle.back()
turtle.turnLeft()
turtle.back()
getamountfrominventory(amountneeded)
turtle.forward()
turtle.turnRight()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.down()
end
function getnotgates(amountneeded)
turtle.up()
turtle.back()
turtle.back()
turtle.back()
turtle.turnLeft()
turtle.back()
turtle.back()
turtle.back()
getamountfrominventory(amountneeded)
turtle.forward()
turtle.forward()
turtle.forward()
turtle.turnRight()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.down()
end
function getmotors(amountneeded)
turtle.up()
turtle.back()
turtle.back()
turtle.turnLeft()
turtle.back()
turtle.back()
getamountfrominventory(amountneeded)
turtle.forward()
turtle.forward()
turtle.turnRight()
turtle.forward()
turtle.forward()
turtle.down()
end
function getbatterybox(amountneeded)
turtle.up()
turtle.back()
turtle.back()
turtle.turnLeft()
turtle.back()
turtle.back()
turtle.back()
turtle.back()
getamountfrominventory(amountneeded)
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.turnRight()
turtle.forward()
turtle.forward()
turtle.down()
end
function getbattery()
turtle.up()
turtle.back()
turtle.back()
turtle.back()
turtle.turnLeft()
turtle.back()
turtle.back()
turtle.back()
turtle.back()
turtle.back()
turtle.suckDown()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.turnRight()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.down()
end
function getscrewdriver()
turtle.up()
for n=1, 4 do turtle.back() end
turtle.suckDown()
for n=1, 4 do turtle.forward() end
turtle.down()
end
function dropoffscrewdriver()
turtle.up()
for n=1, 4 do turtle.back() end
turtle.dropDown()
for n=1, 4 do turtle.forward() end
turtle.down()
end
function getredwire(amountneeded)
turtle.up()
turtle.back()
turtle.back()
turtle.back()
turtle.back()
turtle.turnLeft()
turtle.back()
turtle.back()
getamountfrominventory(amountneeded)
turtle.forward()
turtle.forward()
turtle.turnRight()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.down()
end
function getbluewire(amountneeded)
turtle.up()
turtle.back()
turtle.back()
turtle.back()
turtle.back()
turtle.turnLeft()
turtle.back()
turtle.back()
turtle.back()
turtle.back()
getamountfrominventory(amountneeded)
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.turnRight()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.down()
end
function makebaseframefloor()
turtle.up()
turtle.forward()
for m=1, 3 do
for n=1, 6 do
turtle.placeDown()
turtle.forward()
end
turtle.turnRight()
turtle.forward()
turtle.turnRight()
turtle.forward()
for n=1, 6 do
turtle.placeDown()
turtle.forward()
end
turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
turtle.forward()
end
turtle.up()
turtle.forward()
turtle.turnLeft()
turtle.forward()
turtle.forward()
turtle.placeDown()
turtle.forward()
turtle.forward()
turtle.placeDown()
turtle.forward()
turtle.placeDown()
turtle.turnRight()
turtle.forward()
turtle.turnRight()
turtle.forward()
turtle.placeDown()
turtle.forward()
turtle.placeDown()
turtle.forward()
turtle.placeDown()
turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
turtle.forward()
turtle.placeDown()
turtle.forward()
turtle.placeDown()
turtle.forward()
turtle.placeDown()
turtle.turnRight()
turtle.forward()
turtle.turnRight()
turtle.placeDown()
turtle.forward()
turtle.forward()
turtle.placeDown()
turtle.forward()
turtle.placeDown()
for n=1, 4 do turtle.back() end
turtle.turnLeft()
for n=1, 5 do turtle.back() end
turtle.down()
turtle.down()
end
function placepanels()
turtle.up()
turtle.forward()
for n=1, 4 do
turtle.forward()
turtle.forward()
turtle.turnRight()
turtle.forward()
turtle.place()
turtle.back()
turtle.turnLeft()
for m=1, 3 do turtle.forward() end
turtle.turnRight()
end
turtle.back()
turtle.down()
end
function placenotgates()
turtle.up()
turtle.forward()
for n=1, 4 do
turtle.forward()
turtle.forward()
turtle.turnRight()
turtle.digDown()
turtle.down()
turtle.dig()
turtle.up()
turtle.place()
turtle.down()
turtle.select(2)
turtle.place()
turtle.up()
turtle.placeDown()
turtle.select(1)
turtle.turnLeft()
for m=1, 3 do turtle.forward() end
turtle.turnRight()
end
turtle.back()
turtle.down()
end
function placemotorsinside()
for m=1, 2 do turtle.up() end
turtle.forward()
turtle.forward()
turtle.turnRight()
turtle.forward()
for n=1, 4 do
turtle.forward()
turtle.turnLeft()
turtle.place()
turtle.turnRight()
turtle.forward()
turtle.forward()
turtle.turnLeft()
end
turtle.back()
turtle.turnLeft()
turtle.back()
turtle.back()
for m=1, 2 do turtle.down() end
end
function placemotorsoutside()
turtle.up()
turtle.forward()
turtle.turnRight()
for n=1, 4 do
turtle.forward()
turtle.forward()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.turnLeft()
turtle.placeUp()
turtle.turnLeft()
turtle.turnLeft()
turtle.back()
turtle.select(2)
turtle.place()
turtle.select(1)
turtle.turnRight()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.turnLeft()
end
turtle.turnLeft()
turtle.back()
turtle.down()
turtle.down()
end
function adjustmotors()
for m=1, 3 do turtle.up() end
for m=1, 2 do turtle.forward() end
turtle.turnRight()
for m=1, 2 do turtle.forward() end
for m=1, 3 do turtle.placeDown() end
for m=1, 2 do turtle.forward() end
for n=1, 2 do
turtle.turnLeft()
turtle.forward()
for m=1, 3 do turtle.placeDown() end
for m=1, 2 do turtle.forward() end
end
turtle.turnLeft()
turtle.forward()
for m=1, 3 do turtle.placeDown() end
turtle.turnLeft()
turtle.forward()
for n=1, 4 do
turtle.placeDown()
turtle.forward()
turtle.turnRight()
end
turtle.back()
turtle.back()
turtle.turnLeft()
turtle.back()
turtle.back()
turtle.back()
turtle.back()
for m=1, 4 do turtle.down() end
end
function placebatteryboxes()
for m=1, 3 do turtle.up() end
turtle.forward()
turtle.forward()
turtle.turnRight()
turtle.forward()
for n=1, 4 do
turtle.forward()
turtle.turnLeft()
turtle.place()
turtle.turnRight()
turtle.forward()
turtle.forward()
turtle.turnLeft()
end
turtle.back()
turtle.turnLeft()
turtle.back()
turtle.back()
for m=1, 3 do turtle.down() end
end
function placesecondframeset()
for m=1, 4 do turtle.up() end
turtle.forward()
turtle.forward()
turtle.turnRight()
turtle.forward()
for n=1, 4 do
turtle.down()
turtle.placeDown()
turtle.up()
turtle.placeDown()
for m=1, 2 do turtle.forward() end
turtle.placeDown()
turtle.forward()
turtle.turnLeft()
end
turtle.back()
turtle.turnLeft()
turtle.back()
turtle.back()
for m=1, 4 do turtle.down() end
end
function placeupmotors()
for m=1, 4 do turtle.up() end
for m=1, 3 do turtle.forward() end
turtle.turnRight()
turtle.forward()
turtle.forward()
turtle.turnLeft()
turtle.place()
turtle.digDown()
turtle.down()
turtle.turnRight()
turtle.turnRight()
turtle.placeUp()
turtle.forward()
turtle.turnRight()
turtle.turnRight()
turtle.select(2)
turtle.place()
turtle.select(1)
turtle.back()
turtle.turnRight()
turtle.back()
turtle.back()
turtle.turnLeft()
turtle.back()
for m=1, 3 do turtle.down() end
end
function adjustupmotors()
for m=1, 5 do turtle.up() end
for m=1, 3 do turtle.forward() end
turtle.turnRight()
for m=1, 2 do turtle.forward() end
for m=1, 2 do turtle.placeDown() end
turtle.turnLeft()
turtle.forward()
for m=1, 2 do turtle.placeDown() end
turtle.back()
turtle.turnRight()
for m=1, 2 do turtle.back() end
turtle.turnLeft()
for m=1, 3 do turtle.back() end
for m=1, 5 do turtle.down() end
end
function placefifthbatbox()
for m=1, 5 do turtle.up() end
for m=1, 3 do turtle.forward() end
turtle.turnRight()
for m=1, 3 do turtle.forward() end
turtle.placeDown()
for m=1, 3 do turtle.back() end
turtle.turnLeft()
for m=1, 3 do turtle.back() end
for m=1, 5 do turtle.down() end
end
function placedownmotors()
for m=1, 5 do turtle.up() end
for m=1, 5 do turtle.forward() end
turtle.turnRight()
for m=1, 3 do turtle.forward() end
turtle.turnRight()
turtle.forward()
turtle.place()
turtle.back()
turtle.place()
turtle.turnLeft()
for m=1, 3 do turtle.back() end
turtle.turnLeft()
for m=1, 5 do turtle.back() end
for m=1, 5 do turtle.down() end
end
function placesomeframes()
for m=1, 5 do turtle.up() end
for m=1, 2 do turtle.forward() end
turtle.turnRight()
for n=1, 2 do
turtle.forward()
turtle.placeDown()
end
for n=1, 2 do
for m=1, 2 do turtle.forward() end
turtle.turnLeft()
turtle.placeDown()
turtle.forward()
turtle.placeDown()
end
for n=1, 2 do
turtle.forward()
turtle.placeDown()
end
turtle.turnLeft()
turtle.forward()
turtle.placeDown()
for m=1, 2 do turtle.forward() end
turtle.turnLeft()
turtle.back()
turtle.turnLeft()
for m=1, 2 do turtle.back() end
for m=1, 5 do turtle.down() end
end
function placesecondpanels()
for m=1, 4 do turtle.up() end
for m=1, 3 do turtle.forward() end
turtle.turnRight()
turtle.forward()
turtle.placeDown()
for m=1, 2 do turtle.up() end
for m=1, 3 do turtle.forward() end
turtle.down()
turtle.placeDown()
turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
turtle.down()
turtle.placeDown()
for m=1, 2 do turtle.up() end
for m=1, 3 do turtle.forward() end
turtle.down()
turtle.placeDown()
turtle.forward()
turtle.turnRight()
for m=1, 4 do turtle.back() end
for m=1, 5 do turtle.down() end
end
function placesecondnotgates()
for m=1, 6 do turtle.up() end
for m=1, 4 do turtle.forward() end
turtle.turnRight()
turtle.forward()
turtle.placeDown()
for m=1, 3 do turtle.forward() end
turtle.down()
turtle.turnRight()
turtle.turnRight()
turtle.placeDown()
turtle.up()
for m=1, 4 do turtle.forward() end
turtle.turnRight()
for m=1, 4 do turtle.back() end
for m=1, 6 do turtle.down() end
end
function placemoreframes()
for m=1, 2 do turtle.up() end
turtle.forward()
for n=1, 4 do
for m=1, 3 do turtle.forward() end
turtle.placeDown()
for m=1, 2 do turtle.forward() end
turtle.turnRight()
end
turtle.up()
turtle.forward()
turtle.place()
turtle.back()
turtle.turnRight()
turtle.forward()
turtle.forward()
turtle.place()
turtle.up()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.turnLeft()
turtle.forward()
turtle.place()
turtle.back()
turtle.back()
turtle.turnRight()
for m=1, 5 do turtle.back() end
turtle.turnLeft()
for m=1, 4 do turtle.down() end
end
function placemorepanels()
for m=1, 2 do turtle.up() end
turtle.forward()
for n=1, 4 do
for m=1, 3 do turtle.forward() end
turtle.placeDown()
for m=1, 2 do turtle.forward() end
turtle.turnRight()
end
for m=1, 2 do turtle.up() end
for m=1, 2 do turtle.forward() end
turtle.placeDown()
for m=1, 2 do turtle.back() end
turtle.turnRight()
for m=1, 3 do turtle.forward() end
turtle.placeDown()
turtle.turnLeft()
turtle.forward()
turtle.placeDown()
turtle.turnRight()
turtle.up()
for m=1, 2 do turtle.forward() end
turtle.turnLeft()
turtle.forward()
turtle.placeDown()
for m=1, 3 do turtle.back() end
turtle.turnRight()
for m=1, 5 do turtle.back() end
turtle.turnLeft()
for m=1, 5 do turtle.down() end
end
function placeredwire()
turtle.up()
turtle.up()
turtle.turnLeft()
turtle.forward()
turtle.turnRight()
for n=1, 4 do
for m=1, 4 do turtle.forward() end
turtle.turnRight()
turtle.place()
turtle.turnLeft()
for m=1, 3 do turtle.forward() end
turtle.turnRight()
end
for m=1, 3 do turtle.up() end
for m=1, 3 do turtle.forward() end
turtle.turnRight()
for n=1, 2 do
turtle.forward()
turtle.placeDown()
end
turtle.up()
for m=1, 2 do turtle.forward() end
for n=1, 2 do
turtle.forward()
turtle.placeDown()
end
for m=1, 5 do turtle.back() end
turtle.turnLeft()
for m=1, 3 do turtle.back() end
for m=1, 6 do turtle.down() end
end
function placebluewire()
for m=1, 5 do turtle.up() end
turtle.forward()
turtle.turnRight()
for m=1, 3 do turtle.forward() end
turtle.placeDown()
turtle.turnLeft()
turtle.forward()
turtle.placeDown()
turtle.back()
turtle.back()
turtle.turnRight()
for m=1, 3 do turtle.back() end
turtle.turnLeft()
for m=1, 5 do turtle.down() end
end
function placeright()
turtle.turnRight()
turtle.place()
turtle.turnLeft()
end
function placeleft()
turtle.turnLeft()
turtle.place()
turtle.turnRight()
end
function placeshellpartone()
turtle.up()
turtle.turnLeft()
turtle.forward()
turtle.turnRight()
for i=1, 4 do
for n=1, 4 do
for m=1, 6 do
turtle.forward()
placeright()
end
turtle.forward()
turtle.turnRight()
end
turtle.up()
end
for m=1, 5 do turtle.down() end
turtle.turnRight()
turtle.forward()
turtle.turnLeft()
end
function placeshellparttwo()
for m=1, 4 do turtle.up() end
turtle.turnRight()
for m=1, 4 do turtle.forward() placeleft() end
turtle.forward()
turtle.forward()
turtle.up()
turtle.turnLeft()
for n=1, 4 do
for m=1, 6 do
turtle.forward()
placeleft()
end
turtle.forward()
turtle.turnLeft()
end
turtle.up()
turtle.up()
turtle.forward()
turtle.turnLeft()
turtle.forward()
turtle.turnRight()
for n=1, 3 do
for m=1, 6 do
turtle.placeDown()
turtle.forward()
end
turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
turtle.forward()
for m=1, 6 do
turtle.placeDown()
turtle.forward()
end
turtle.turnRight()
turtle.forward()
turtle.turnRight()
turtle.forward()
end
turtle.forward()
turtle.forward()
turtle.turnRight()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.digDown()
turtle.down()
turtle.placeDown()
turtle.up()
turtle.placeDown()
turtle.back()
turtle.back()
turtle.turnLeft()
turtle.back()
turtle.back()
turtle.back()
for m=1, 7 do turtle.down() end
end
function givepower()
for m=1, 5 do turtle.up() end
for m=1, 6 do turtle.back() end
turtle.turnRight()
turtle.forward()
turtle.forward()
for n=1, 3 do
redstone.setOutput("bottom", true)
sleep(0.5)
redstone.setOutput("bottom", false)
sleep(0.5)
end
sleep(30)
turtle.forward()
turtle.forward()
turtle.forward()
for n=1, 3 do
redstone.setOutput("bottom", true)
sleep(0.5)
redstone.setOutput("bottom", false)
sleep(0.5)
end
for m=1, 5 do turtle.back() end
turtle.turnLeft()
for m=1, 6 do turtle.forward() end
for m=1, 5 do turtle.down() end
end
function moveengineup()
for m=1, 4 do turtle.up() end
turtle.turnLeft()
turtle.forward()
turtle.turnRight()
for m=1, 3 do turtle.forward() end
turtle.turnRight()
redstone.setOutput("front", true)
sleep(0.5)
redstone.setOutput("front", false)
turtle.turnLeft()
for m=1, 3 do turtle.back() end
turtle.turnLeft()
turtle.back()
turtle.turnRight()
for m=1, 4 do turtle.down() end
end
getframes(48)
makebaseframefloor()
getpanels(4)
placepanels()
getnotgates(4)
placenotgates()
getmotors(8)
placemotorsinside()
placemotorsoutside()
getscrewdriver()
adjustmotors()
dropoffscrewdriver()
getbatterybox(4)
placebatteryboxes()
getframes(12)
placesecondframeset()
getmotors(2)
placeupmotors()
getscrewdriver()
adjustupmotors()
dropoffscrewdriver()
getbatterybox(1)
placefifthbatbox()
getmotors(2)
placedownmotors()
getframes(9)
placesomeframes()
getpanels(4)
placesecondpanels()
getnotgates(2)
placesecondnotgates()
getframes(7)
placemoreframes()
getpanels(8)
placemorepanels()
getredwire(8)
placeredwire()
getbluewire(2)
placebluewire()
getframes(64)
placeshellpartone()
getframes(59)
placeshellparttwo()
givepower()
moveengineup()