This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Skampi's profile picture

XP - Turtle + Monitor [Lua]

Started by Skampi, 02 April 2013 - 03:34 AM
Skampi #1
Posted 02 April 2013 - 05:34 AM
Hey, i've been writing an auto - book - enchanting program using a XP - Turtle.
It waits till it's 30 and then picks a book and so on and so on.
It's all working fine, but now i wanted to hook up a monitor so it can display the levels if it's not level 30 yet.

Here's the code (the monitor is on the top of the turtle) :
m = peripheral.wrap("right")
monitor = peripheral.wrap("top")

local o = 0
local x = 0

m.setAutoCollect(true)
x = 1

while x == 1 do
if m.getLevels() > 29 then
turtle.select(1)
turtle.suck()
turtle.drop(turtle.getItemCount(1)-1)
m.enchant(30)
turtle.drop()
else
m.getLevels(o)
monitor.setCursorPos(2, 2)
monitor.write(o)
sleep(10)
end
end

My problem now it that it's not running endless, it stops after the first run and is not showing the level.
I would love to see the problem fixed, please help me out. :)/>

This was my first post, i hope i did everything right and don't look that dumb,
sincerely,
Skampi.
D3add3d #2
Posted 02 April 2013 - 05:56 AM
Solution:

m = peripheral.wrap("right")
monitor = peripheral.wrap("top")

local o = nil

m.setAutoCollect(true)

while true do
if m.getLevels() > 29 then
  turtle.select(1)
  turtle.suck()
  turtle.drop(turtle.getItemCount(1)-1)
  m.enchant(30)
  turtle.drop()
else
  o = m.getLevels()
  monitor.setCursorPos(2, 2)
  monitor.write(o)
  sleep(10)
end
end
It was not running endlessly because of the same problem it did not print anything to monitor… you must set variable to something, not give an argument to function what can not have any.
Skampi #3
Posted 02 April 2013 - 06:44 AM
Oh, okay, thank you very much. :)/>