Posted 02 March 2015 - 12:25 AM
I made this code for a turtle to act as a 3D printer. I have a file called "print," and it should wait until it gets a print request, then list what materials it needs. The problem is that it's not showing any text on-screen. Here's the code:
function print()
while ypos < #blocks do
while xpos - minx < maxx - minx do
while zpos - minz < maxz - minz do
turtle.digDown()
if not (blocks[ypos][xpos - minx][zpos - minz] == 0) then
turtle.select(blocks[ypos][xpos - minx][zpos - minz])
turtle.digDown()
turtle.placeDown()
end
turtle.dig()
turtle.forward()
if dir == 1 then
zpos = zpos + 1
else
zpos = zpos - 1
end
end
turtle.turnRight()
turtle.forward()
if dir == 1 then
xpos = xpos + 1
dir = 2
else
xpos = xpos - 1
dir = 1
end
turtle.turnRight()
end
end
end
slots = {0,0,0,0,0,0,0,0}
function sort(arg)
minx = math.huge
maxx = 0
minz = math.huge
maxz = 0
for y=1,#arg,1 do
for x=1,#arg[y],1 do
for z=1,#arg[y][x],1 do
if not (arg[y][x][z] == 0) then
slots[arg[y][x][z]] = slots[arg[y][x][z]] + 1
if x > maxx then
maxx = x
elseif x < minx then
minx = x
elseif z > maxz then
maxz = z
elseif z < minz then
minz = z
end
end
end
end
end
end
id = os.getComputerID()
modem = peripheral.wrap("right")
modem.open(123)
modem.open(124)
printing = 0
xpos = 1
ypos = 1
zpos = 1
dir = 1
local timer = os.startTimer(3)
while true do
if printing == 0 then
modem.transmit(123,123,id)
event,a,b,c,d = os.pullEvent()
if (event == "timer" and a == timer) then
timer = os.startTimer(3)
elseif (event == "modem_message" and c == id) then
if tonumber(d) == nil then
slots = {0,0,0,0,0,0,0,0}
blocks = d
sort(blocks)
term.clear()
term.setCursorPos(1,1)
term.setTextColor(colors.white)
for i=1,8,1 do
print("Slot "..i..":"..slots.." blocks")
end
print("Click anywhere to continue.")
e = os.pullEvent("mouse_click")
term.clear()
end
end
end
end
function print()
while ypos < #blocks do
while xpos - minx < maxx - minx do
while zpos - minz < maxz - minz do
turtle.digDown()
if not (blocks[ypos][xpos - minx][zpos - minz] == 0) then
turtle.select(blocks[ypos][xpos - minx][zpos - minz])
turtle.digDown()
turtle.placeDown()
end
turtle.dig()
turtle.forward()
if dir == 1 then
zpos = zpos + 1
else
zpos = zpos - 1
end
end
turtle.turnRight()
turtle.forward()
if dir == 1 then
xpos = xpos + 1
dir = 2
else
xpos = xpos - 1
dir = 1
end
turtle.turnRight()
end
end
end
slots = {0,0,0,0,0,0,0,0}
function sort(arg)
minx = math.huge
maxx = 0
minz = math.huge
maxz = 0
for y=1,#arg,1 do
for x=1,#arg[y],1 do
for z=1,#arg[y][x],1 do
if not (arg[y][x][z] == 0) then
slots[arg[y][x][z]] = slots[arg[y][x][z]] + 1
if x > maxx then
maxx = x
elseif x < minx then
minx = x
elseif z > maxz then
maxz = z
elseif z < minz then
minz = z
end
end
end
end
end
end
id = os.getComputerID()
modem = peripheral.wrap("right")
modem.open(123)
modem.open(124)
printing = 0
xpos = 1
ypos = 1
zpos = 1
dir = 1
local timer = os.startTimer(3)
while true do
if printing == 0 then
modem.transmit(123,123,id)
event,a,b,c,d = os.pullEvent()
if (event == "timer" and a == timer) then
timer = os.startTimer(3)
elseif (event == "modem_message" and c == id) then
if tonumber(d) == nil then
slots = {0,0,0,0,0,0,0,0}
blocks = d
sort(blocks)
term.clear()
term.setCursorPos(1,1)
term.setTextColor(colors.white)
for i=1,8,1 do
print("Slot "..i..":"..slots.." blocks")
end
print("Click anywhere to continue.")
e = os.pullEvent("mouse_click")
term.clear()
end
end
end
end