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

[Lua][Error] attempt to index ? (a nil value)

Started by Heliomance, 02 February 2013 - 05:41 AM
Heliomance #1
Posted 02 February 2013 - 06:41 AM
[Lua][Error] attempt to index ? (a nil value)

I'm trying my hand at getting a turtle to build a structure for me - once I've got it working I'm going to use it to build a base under the surface of lava. Unfortunately, I keep getting that error. Here's a link to pastebin - I've imported it directly to the turtle using the pastebin command. And yes, it's defintiely a turtle not a computer.

http://pastebin.com/VvVPPhMF
ikke009 #2
Posted 02 February 2013 - 06:46 AM
do sleep(0.1) instead of sleep 0.1
that should fix it
Heliomance #3
Posted 02 February 2013 - 07:10 AM
Nope, still giving exactly the same error.

New file (I only just made a pastebin account): http://pastebin.com/S1HwYeRt
remiX #4
Posted 02 February 2013 - 09:52 AM
Can you at least tell us which line?!
KingMachine #5
Posted 02 February 2013 - 11:27 AM
Nope, still giving exactly the same error.

New file (I only just made a pastebin account): http://pastebin.com/S1HwYeRt

Using this code I get no errors. Try rebooting minecraft (server and client). Sometimes things get jumbled up in there.
Roonagooo #6
Posted 02 February 2013 - 11:06 PM
you should get a error [number] attempt to index a nul value what is the number if possible could you please tell then maybe people can help more as opposed to trying to look through the whole code to find the error.
etopsirhc #7
Posted 02 February 2013 - 11:22 PM
unless you are setting turtle.right to turtle.turnRight ( as well as the lefts ) then that would be the biggest problem
BlackDragon #8
Posted 03 February 2013 - 12:15 AM
Your whole program is wrapped in a function but the function is never called, How are you executing the program?
Heliomance #9
Posted 03 February 2013 - 01:20 AM
Can you at least tell us which line?!
Oh, sorry - line 1
Your whole program is wrapped in a function but the function is never called, How are you executing the program?


>pastebin get S1HwYeRt basetest
>lua
>basetest.buildBase()
remiX #10
Posted 03 February 2013 - 01:27 AM
you need to do os.loadAPI("basetest") first before using it as an API.
Heliomance #11
Posted 03 February 2013 - 03:48 AM
What exactly is an API, and how are you supposed to run programs if that's not it?
remiX #12
Posted 03 February 2013 - 06:21 AM
An API is not meant to be the main program. An API is a program but, it ONLY contains functions for future use when you load it from another program.

People would use it to make their main program 'neater' if the functions within the API are not needed to be edited to suit the programs needs.

Example:
Make a program and call it 'myAPI' in the computers main folder.
Open it and add this to it:

function hello()
    print("Hello there! Do i know you?")
end

Now you main program have this:

os.loadAPI("myAPI")

print("Line")
myAPI.hello()
print("You should know me :(/>")

Output:

Line
Hello there! Do i know you?
You show know me :(/>

Now it called the functions from the API and ran it.
Heliomance #13
Posted 03 February 2013 - 07:09 AM
So I should take out the function wrapper, and then just calling basetest will work?

Yep, that worked. Thanks for the help, all!