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

tim:28: attempt to index ? (a nil value)

Started by Poketostorm, 22 April 2013 - 01:16 AM
Poketostorm #1
Posted 22 April 2013 - 03:16 AM
I can't start a new topic for some reason. Anyway, I need help! I'm trying to use this script:

– @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
end

But it says "tim:28: attempt to index ? (a nil value)"
Tim is the name of the program.
Help?
MistahEpic #2
Posted 22 April 2013 - 03:35 AM
I can't start a new topic for some reason. Anyway, I need help! I'm trying to use this script:

– @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
end

But it says "tim:28: attempt to index ? (a nil value)"
Tim is the name of the program.
Help?

i believe youre supposed to post questions on here when you cant make a new topic.
Bubba #3
Posted 22 April 2013 - 08:24 AM
Use pastebin if you have a specific line that is erroring. I can't even tell what line 28 is.
Poketostorm #4
Posted 22 April 2013 - 11:16 PM
Wait so that means it's an error on line 28?

-- @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
end

Is that what you mean by pastebin? Sorry, I'm a noob at this…
theoriginalbit #5
Posted 22 April 2013 - 11:22 PM
Wait so that means it's an error on line 28?
Indeed, any good error message follows this format
<file-name>:<line number>:<what is wrong>

Is that what you mean by pastebin? Sorry, I'm a noob at this…
No that is code tags, its better though. what was meant was go to http://pastebin.com and paste the code into the box and press submit, then just give us the url, instead of pasting the code here with its bad fomatting
Poketostorm #6
Posted 22 April 2013 - 11:59 PM
Got the script from here: https://github.com/authorblues/cc-scripts/blob/master/tim.lua
Pastebin: http://pastebin.com/m7jAhTM3
theoriginalbit #7
Posted 23 April 2013 - 12:03 AM
Ok so this is an XP Turtle using the XP peripheral I'm assuming?
Well on line 15 where it says

local xp = peripheral.wrap("right")
change the "right" to which ever side of the turtle the peripheral is attached.
Poketostorm #8
Posted 23 April 2013 - 12:18 AM
Would it be 'front'?
theoriginalbit #9
Posted 23 April 2013 - 12:22 AM
Well there is 'left', 'right', 'top', 'bottom', 'front', 'back'
So without seeing it, idk… where is the peripheral when looking at the front of the computer? If it is on your left then 'left', on your right then 'right', near you, 'front', etc, etc.
Poketostorm #10
Posted 23 April 2013 - 03:07 AM
Well, it's still having the problem with line 28.
theoriginalbit #11
Posted 23 April 2013 - 03:09 AM
can you upload an image of your setup?
Poketostorm #12
Posted 23 April 2013 - 03:16 AM
Umm… I can't find the file attachment button…
theoriginalbit #13
Posted 23 April 2013 - 03:19 AM
just use something like imgur or puush
Poketostorm #14
Posted 23 April 2013 - 03:21 AM
http://imgur.com/gWv208x
theoriginalbit #15
Posted 23 April 2013 - 03:25 AM
Can I see the right side of the turtle please.
Poketostorm #16
Posted 23 April 2013 - 03:29 AM
http://imgur.com/e5KrUL9,CUOKPUS#0
theoriginalbit #17
Posted 23 April 2013 - 03:30 AM
where is the XP peripheral?
Left = Diamond Sword
Right = None
Top = Never can have
Bottom = Engine
Front = Never can have
Back = Chest
Edited on 23 April 2013 - 01:31 AM
Poketostorm #18
Posted 23 April 2013 - 03:36 AM
ANNNNND I FOUND OUT I NEED AN ENCHANTING TABLE

THANK YOU FOR REVEALING MY IDIOCY TO ME
:'D
Poketostorm #19
Posted 23 April 2013 - 03:42 AM
Sorry for the caps… I thought it was weird a turtle could enchant with nothing but a sword…
So that's what you meant by an XP Peripheral? An enchanting table added onto a turtle?
theoriginalbit #20
Posted 23 April 2013 - 03:56 AM
So that's what you meant by an XP Peripheral? An enchanting table added onto a turtle?
Yes. Requires MiscPeripherals to be installed iirc.