Jump to content




[Solved] Attempt to call nil?


  • You cannot reply to this topic
5 replies to this topic

#1 SnacksMuffs

  • New Members
  • 2 posts

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 by SnacksMuffs, 04 January 2016 - 03:41 AM.


#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 03 January 2016 - 07:26 PM

Moved to Ask a Pro.

#3 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

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.

#4 SnacksMuffs

  • New Members
  • 2 posts

Posted 04 January 2016 - 03:39 AM

View PostKingofGamesYami, on 03 January 2016 - 07:33 PM, said:

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!

#5 dan200

  • Administrators
  • 542 posts
  • LocationCambridge, England

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

#6 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

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. :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users