Posted 14 September 2013 - 11:23 AM
                Title: Help with EP-Turtle-Code
Hello,
I wanted to ask how to edit this code I found, so I can place the monitor in the back of the turtle.
Thank you. -SgtEntenbraten
                
            Hello,
I wanted to ask how to edit this code I found, so I can place the monitor in the back of the turtle.
-- @param attacks between inventory dump
local t = 256
-- @param level to do enchantments
local enchantLevel = 30
-- @param monitor direction (can be nil if no monitor)
local monitorSide = nil
-- @param experience per kill (use 0 if you don't know)
-- this will be used to estimate the number of kills
local XPperKill = 0
-- wrap all peripherals
local xp = peripheral.wrap("right")
local mtr = term
-- if the monitor side was set, wrap it
if monitorSide ~= nil then
  mtr = peripheral.wrap(monitorSide)
  if mtr == nil then mtr = term end
end
local color = mtr.isColor()
local name = "Tim the Enchanter v1.0"
local enchants = 0
local totalXP = xp.get()
xp.setAutoCollect(false)
mtr.setCursorBlink(false)
local function display()
  local level = xp.getLevels()
  local W,H = mtr.getSize()
  local row = 4
  if color then
	mtr.setBackgroundColor(colors.black)
  end
  mtr.clear()
  -- write program name and decoration
  mtr.setCursorPos((W-#name)/2, 1)
  mtr.write(name)
  mtr.setCursorPos(1,2)
  mtr.write(string.rep("-", W))
  -- get the length of the progress bar
  local barWidth = W-7
  local barFill = (level * barWidth) / enchantLevel
  if barFill > barWidth then barFill = barWidth end
  -- write the level progress bar
  mtr.setCursorPos(2, row)
  mtr.write("L")
  mtr.setCursorPos(W-2, row)
  mtr.write(string.format("%02d", level))
  if color then
	mtr.setCursorPos(4, row)
	mtr.setBackgroundColor(colors.lightGray)
	mtr.write(string.rep(" ", barWidth))
	mtr.setCursorPos(4, row)
	mtr.setBackgroundColor(colors.red)
	mtr.write(string.rep(" ", barFill))
	-- reset background color
	mtr.setBackgroundColor(colors.black)
  else
	mtr.setCursorPos(4, row)
	mtr.write(string.rep("-", barWidth))
	mtr.setCursorPos(4, row)
	mtr.write(string.rep("#", barFill))
  end
  row = row + 2
  -- write the enchantment info
  mtr.setCursorPos(2, row)
  mtr.write("E")
  local enchantInfo = string.format("%d enchants", enchants)
  mtr.setCursorPos(W-(#enchantInfo), row)
  mtr.write(enchantInfo)
  row = row + 2
  if XPperKill > 0 then
	-- write the kill info
	mtr.setCursorPos(2, row)
	mtr.write("K")
	local killInfo = string.format("~ %d kills", math.floor(totalXP / XPperKill))
	mtr.setCursorPos(W-(#killInfo), row)
	mtr.write(killInfo)
	row = row + 2
  end
  -- write the experience info
  mtr.setCursorPos(2, row)
  mtr.write("XP")
  local xpInfo = string.format("%d total XP", totalXP)
  mtr.setCursorPos(W-(#xpInfo), row)
  mtr.write(xpInfo)
  row = row + 2
end
while true do
  display()
  -- attack and pick up items
  for i=1,t do
	turtle.attack()
	turtle.suck()
	totalXP = totalXP + xp.collect()
  end
  -- empty contents of turtle inventory  
  for i=14,1,-1 do
	turtle.select(i)
	turtle.dropDown()
  end
  -- if we have enough levels to enchant
  if xp.getLevels() >= enchantLevel
  then
	-- toss buffered enchant
	turtle.select(16)
	turtle.dropDown()
	-- get more of whatever we are enchanting
	turtle.select(15)
	if turtle.getItemCount(15) == 0 then turtle.suckUp() end
	turtle.transferTo(16, 1)
	-- select the enchant slot and do it
	turtle.select(16)
	xp.enchant(enchantLevel)
	enchants = enchants + 1
	-- hold on to item to "buffer" (so we can see it)
	turtle.select(1)
  end
endThank you. -SgtEntenbraten
 
        