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

attempt to index ? (a nil value)

Started by oBoLLl, 23 March 2013 - 06:39 AM
oBoLLl #1
Posted 23 March 2013 - 07:39 AM
Good day!
I try to create a melee turtle with the code:

http://pastebin.com/NFj2Taja

Spoiler

local junkItem = true
local count = 0
local sides = {"top","bottom","right","left","back"}
term.clear()
term.setCursorPos(1,1)function drop(side)
if side == "left" then
  turtle.turnLeft()
  turtle.drop()
  turtle.turnRight()
elseif side == "right" then
  turtle.turnRight()
  turtle.drop()
  turtle.turnLeft()
elseif side == "top" then
  turtle.dropUp()
elseif side == "bottom" then
  turtle.dropDown()
elseif side == "back" then
  turtle.turnLeft()
  turtle.turnLeft()
  turtle.drop()
  turtle.turnLeft()
  turtle.turnLeft()
end
end
print("Welcome to Engineer's mob destroyer!")if turtle.getItemCount(1) == 0  and junkItem == true then
print("Put in slot 1 your 'junk' item")
while true do
  if turtle.getItemCount(1) > 0 then
   break
  end
  sleep(0)
end
end
if not fs.exists("/chestPositions") then
local ask_junk = true
local ask_misc = true
while ask_junk do
  term.setCursorPos(1, 3)
  term.clearLine()
  print("What side is your 'junk' chest?")
  junkSide = string.lower(read())
  for i = 1, 5 do
   if junkSide == sides[i] then
	ask_junk = false
	break
   end
  end
end
while ask_misc do
  term.setCursorPos(1, 4)
  term.clearLine()
  print("What side is your good items chest?")
  goodSide = string.lower(read())
  for i = 1, 5 do
   if goodSide == sides[i] then
	ask_misc = false
	break
   end
  end
end
local tTable = {}
tTable.junkSide = junkSide
tTable.goodSide = goodSide
local file = fs.open("/chestPositions", "w")
textutiles.serialize(tTable)   (<=== 72 Line)
file.close()
elseif fs.exists("/chestPositions") then
local file = fs.open("/chestPositions", "r")
local handler = file.readAll()
junkSide = handler.junkSide
goodSide = handler.goodSide
file.close()
end
while true do
turtle.select(2)
turtle.attack()
if turtle.getItemCount(16) > 0 then
  for i = 2, 16 do
   local counter = turtle.getItemCount(i)
   count = count + counter
   term.setCursorPos(1,4)
   term.clearLine()
   print("Loots collected: "..count)
   turtle.select(i)
   if turtle.compareTo(1) then
	drop(junkSide)
   else
	drop(goodSide)
   end
  end
end
sleep(.5)
end

Script at startup every time writing
Farm:72: attempt to index ? (a nil value)

Thank you very much in advance for your help!
LBPHacker #2
Posted 23 March 2013 - 07:46 AM
Wait… textutiles?
textutils.serialize(tTable)

There is no e before the s in textutils.

BTW: line 76. You treat the string returned by .readAll like a table. You may want to unserialize it.
local handler = textutils.unserialize(file.readAll())
Engineer #3
Posted 23 March 2013 - 07:48 AM
Thanks for letting me know on my post I have made for this to post errors and such. :/
Anyway, I have updated the code.

I should rewrite the code once.. but meh..

And for the next time, give at least a credit…

Thanks to LBPHacker for letting me know about this post.
And of course oBolli also, for letting me this know :)/>
oBoLLl #4
Posted 23 March 2013 - 09:10 AM
2LBPHacker, 2Engineer

Guys, Thank You very much to You for Your tips and fixes! From the community MineHack Russia!!!