Posted 01 December 2014 - 09:34 PM
Hi,
I made this simple mining program that tunnels and it record information such as the percentage it is done.
I want to send this information to a computer (Which i have done) and then display it to a monitor (which isnt work). When i display the info on the monitor the percentage done is not updating.
Code for the turtle:
On the monitor i have a code that is on a never ending loop:
So basicly i would like to know how to print text on a monitor that is updating insync with the computer.
Thanks.
I made this simple mining program that tunnels and it record information such as the percentage it is done.
I want to send this information to a computer (Which i have done) and then display it to a monitor (which isnt work). When i display the info on the monitor the percentage done is not updating.
Code for the turtle:
rednet.open("right")
function gravelSides()
while turtle.detect() == true do
turtle.dig()
sleep(1)
end
end
function placeTorch() --Places a torch every 5 blocks (Need to put torches in slot 2)
if x == 5 then
turtle.up()
turtle.turnLeft()
turtle.forward()
turtle.dig()
turtle.select(2)
turtle.place()
turtle.select(1)
turtle.back()
turtle.turnRight()
turtle.down()
x = 0
end
end
function dig() --Digs a 3 x 2
turtle.digUp()
turtle.turnLeft()
turtle.dig()
gravelSides()
turtle.up()
turtle.dig()
gravelSides()
turtle.turnRight()
turtle.turnRight()
turtle.dig()
gravelSides()
turtle.down()
turtle.dig()
gravelSides()
turtle.turnLeft()
turtle.dig()
gravelSides()
placeTorch()
turtle.forward()
x = x + 1
end
function resetTerm() --Resets the GUI
term.clear()
term.setCursorPos(1,1)
end
function checkFuel() --Checks if you have enough fuel
resetTerm()
print("Checking Fuel...")
sleep(2)
if turtle.getFuelLevel() > minFuelAmount then
resetTerm()
print("You have Enough fuel.")
print("Current fuel: "..turtle.getFuelLevel())
print("Starting...")
sleep(3)
else
while (true) do
turtle.refuel(1)
resetTerm()
print("Waiting for fuel...")
print("Current fuel: "..turtle.getFuelLevel())
print("Amount of fuel needed: "..minFuelAmount-turtle.getFuelLevel())
if turtle.getFuelLevel() > minFuelAmount then
print("Have enough fuel.")
print("Starting...")
sleep(4)
break
end
end
end
end
function completed()
done = w / tunnelLength * 100
end
x = 0
w = 0
write("Enter the length of the tunnel: ")
tunnelLength = read()
minFuelAmount = 4 * tunnelLength + tunnelLength
checkFuel()
resetTerm()
for i = 1,tunnelLength do
resetTerm()
print("Digging...")
completed()
rednet.send(4, "Tunnel is: "..done.."% completed.")
print("Tunnel is: "..done.."% completed.")
w = w + 1
dig()
resetTerm()
print("Digging...")
completed()
rednet.send(4, "Tunnel is: "..done.."% completed.") --4 is the ID of the computer
print("Tunnel is: "..done.."% completed.")
end
for o = 0,tunnelLength do
turtle.back()
end
On the monitor i have a code that is on a never ending loop:
while (true) do
rednet.open("back")
id, message = rednet.receive()
local monitor = peripheral.wrap("top")
term.clear()
term.setCursorPos(1, 1)
print("Turtle: "..id.."\n"..message)
monitor.write(message)
end
So basicly i would like to know how to print text on a monitor that is updating insync with the computer.
Thanks.