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

Attempt to index nil. Gives value when checked in lua.

Started by aarondm, 13 February 2013 - 10:46 PM
aarondm #1
Posted 13 February 2013 - 11:46 PM
Hey there.

For some reason, this variable is not being read properly. When I manually check it in lua, I get the right number returned.

I have a turtle receive function:


rednet.open("right")
while true do
	id, msg = rednet.receive()
	amount = tonumber(msg)
	turtle.suckUp()
	turle.drop(amount)
	turtle.dropDown()
end

and a computer sending function:


rednet.open("top")
    term.setCursorPos(1,1)
print("What item would you like?")
    item = read()
    shell.run("clear")
    term.setCursorPos(1,1)
print("You asked for " ..item.. ".")
print("How many would you like?")
    amount = read()
    shell.run("clear")
    term.setCursorPos(1,1)
    quantity = tostring(amount)
if item == "cobblestone" then
    rednet.send(1,quantity)
  elseif item == "dirt" then
    rednet.send(35,quantity)
end
print("Fetching " ..amount.. " " ..item)
print("Your items are in the chest.")
    sleep(2)
    shell.run("reboot")

The turtle is receiving the right number, I'm just not sure why it isn't using it in the function on line 6.

Any ideas?
1lann #2
Posted 14 February 2013 - 12:02 AM
Attempt to index nil means you tried to access something as if it's a table, but infact the table does not exist/is nil.
I think the problem would be in this part on line 6 of the receive program (You did a typo):

turle.drop(amount)
aarondm #3
Posted 14 February 2013 - 12:10 AM
Ugh. Nothing is more frustrating then realizing all your prior frustration came from a single typo…

Thank you for providing a fresh set of eyes and seeing what I didn't.