Jump to content




No error thrown, print not working

turtle computer help

  • You cannot reply to this topic
2 replies to this topic

#1 ViperLordX

  • Members
  • 43 posts
  • LocationEarth

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[i].." blocks")
end
print("Click anywhere to continue.")
e = os.pullEvent("mouse_click")
term.clear()
end
end
end
end

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 02 March 2015 - 12:39 AM

You made a function called print, and then you try to use a function called print to write things to the screen, which calls the function you've just declared rather than the one that you can use to write things to the screen. Change your function's name.

#3 ViperLordX

  • Members
  • 43 posts
  • LocationEarth

Posted 02 March 2015 - 01:34 AM

Oh, thanks xD





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users