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

attempt to index ? (a nil value)

Started by MachoMancha, 31 March 2014 - 07:07 PM
MachoMancha #1
Posted 31 March 2014 - 09:07 PM
I've been using the following program successfully for months, until now it's given me some sort of issue. I have the program named startup and here is the program:


local m=peripheral.wrap("top")
local sizeX, sizeY=m.getSize()
function cText(msg, x)
sText=string.len(msg)
size=sizeX/2-sText/2
m.setCursorPos(size, x)
m.write(msg)
end
function text(msg, y)
m.setCursorPos(1, y)
m.write(msg)
end
m.setTextScale(0.9)
sizeX, sizeY=m.getSize()
m.setTextColor(colors.lime)
cText(" How To Become A Member", 2)
m.setTextColor(colors.yellow)
text("1) Register on www.sombrerocraft.com", 5)
text("2) Add your MC character", 7)
text("   (Must be in vannilla MC 1.7.2)", 8)
text("3) Click on 'Join Website' where you logged in", 10)
m.setTextColor(colors.lime)
cText(" Member Benefits", 13)
m.setTextColor(colors.yellow)
text(" - Set two homes", 15)
text(" - Buy from shops", 17)
text(" - Set up to 5 Protection Stones", 19)
text(" - Unique in-game, website and TeamSpeak Member Tags", 21)
text(" - Qualify to level up to Veteran", 23)
text(" - Free surprise Member reward", 25)
m.setTextColor(colors.lime)
cText(" Still not a Member?", 28)
m.setTextColor(colors.yellow)
text("   Relogging won't help. You will receive Member rank", 32)
text("   immediately after successfully completing each step", 34)
Bomb Bloke #2
Posted 31 March 2014 - 10:39 PM
Isn't there any more to the error then that…? Usually there'll be some indication as to eg the line number where the problem occured.
CometWolf #3
Posted 01 April 2014 - 05:29 AM
The only table used here is the wrapped monitor, so chances are it's the problem. Idk if wrap errors if no peripheral is present.
blipman17 #4
Posted 01 April 2014 - 09:34 AM
but what is the error? or what is the unexpected result? or what doesn't work properly? that would really help.
CometWolf #5
Posted 01 April 2014 - 10:04 AM
Read the topic title, lol…
apemanzilla #6
Posted 01 April 2014 - 01:48 PM
Could you please post the COMPLETE error, which should look something like this:
startup: 12: attempt to index ? (a nil value!)
Bomb Bloke #7
Posted 01 April 2014 - 01:59 PM
The only table used here is the wrapped monitor, so chances are it's the problem. Idk if wrap errors if no peripheral is present.

Since you mention it, peripheral.wrap() indeed returns nil (without error) when passed an invalid "side". I'd been assuming maybe he'd wiped "color" or something, but that's probably it.

I can say that 0.9 is not a valid text scale, but again, that on its own shouldn't error.
TheOddByte #8
Posted 01 April 2014 - 03:27 PM
Please post a screenshot of how you have set it up( the monitor & computer )
If you indeed have a monitor ontop of the computer it shouldn't error.
Also, An improvement of you cText function

local function cText( text, y )
    m.setCursorPos( sizeX/2 - #text/2, y )
    m.write( text )
end

--[[
    Using # works like doing string.len( text ), but you can do this 
    local lenghtOfText = #text
--]]