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

[Solved] Attempt to call nil?

Started by SnacksMuffs, 03 January 2016 - 09:35 AM
SnacksMuffs #1
Posted 03 January 2016 - 10:35 AM
term.clear()
term.setCursorPos(1,1)
print("===================================================")
term.setCursorPos(1,18)
print("===================================================")
term.setCursorPos(20,2)
print("Desk Text")
newLine()
newLine()
print("What would you like your desk to say?")
newLine()
write("  Input: ")

local input = read()
mon = peripheral.wrap("left")

function centerText(text)
  x,y = mon.getSize()
  x1,y1 = mon.getCursorPos()
  mon.setCursorPos((math.floor(x/2) - (math.floor(#text/2))), y1)
  mon.write(text)
end

mon.clear()
mon.setTextScale(2)
centerText(input)

newLine()
print(" Text is being displayed on the monitor!")

function newLine()
  local _,cY = term.getCursorPos()
  term.setCursorPos(1, cY+1)
end

The error I keep getting is:

desk:8: attempt to call nil

Maybe it's something simple, but I can't see it. It's also 5:33am
Edited on 04 January 2016 - 02:41 AM
Lyqyd #2
Posted 03 January 2016 - 07:26 PM
Moved to Ask a Pro.
KingofGamesYami #3
Posted 03 January 2016 - 07:33 PM
You're trying to use your newLine function before you define it. Simply move your declaration of newLine to the top of your program.
SnacksMuffs #4
Posted 04 January 2016 - 03:39 AM
You're trying to use your newLine function before you define it. Simply move your declaration of newLine to the top of your program.

That would make so much sense and of course it fixed my problem. Thank you so much!
dan200 #5
Posted 09 January 2016 - 12:01 AM
Closing. Mods: please close bug topics if they've been solved.
Edit: Whoops, thought I was in the bugs forum
Lyqyd #6
Posted 09 January 2016 - 12:58 AM
This topic was originally in the Bugs section, so you likely were in the Bugs section until you followed the topic-movement-trail link that was left behind after I moved it. :)/>