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

[Lua][Error] Attempt to call nil

Started by CODsniperkid, 20 August 2012 - 01:31 PM
CODsniperkid #1
Posted 20 August 2012 - 03:31 PM
I was trying to make a program and I wanted to make the coding simpler to code, so I created a function that clears the screen and sets the cursor position to (1,1). When I try this, it gives me a "client:4:attempt to call nil" error. The code is below of a test program I made to show the error.


print("Type 1 to clean")
type = io.read()
if type == "1" then
clean()
end

function clean()
term.clear()
term.setCursorPos(1,1)
end

Please help :P/>/> Thank you.

EDIT: Do I have to put the function before anything else?
EDIT2: Fixed it. You do :D/>/>
Cranium #2
Posted 20 August 2012 - 03:33 PM
You should put your function before you call it. Lua reads top-down, and in this instance, clean() does not exist until after calling it. Always a good idea to put variables and functions at the top of your code.
Erf10 #3
Posted 28 May 2013 - 06:51 PM
I typed up a script for my moniter and it wont work.. It was this

m = peripheral.wrap("Right")
m.clear()
m.setTextScale(2.5)
m.cursorPos(3,1)
m.write("Hello World!")


and I get this…
screen:4: attempt to call nil.

PLEASE HELP ME :(/>
Engineer #4
Posted 28 May 2013 - 06:54 PM
It should be:

m.setCursorPos ( 1, 2 )