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

Error: can someone please help me with this attempt to index bug?

Started by Zorach, 11 February 2013 - 09:18 PM
Zorach #1
Posted 11 February 2013 - 10:18 PM
Title: Error: can someone please help me with this attempt to index bug?

This keeps the computer ID at the top of the screen whenever something new is printed.

function sortPrint(string)
	local tx, ty = term.getSize()
	local ID = ("Computer ID = ".. tostring(os.computerID()))
	local nx = (tx/2) - (string.len(ID)/2)
	print(string)
	local x, y = term.getCursorPos()
	term.setCursorPos(nx, 1)
	term.clearLine()
	term.write(ID)
	term.setCursorPos(x,y)
end
​
I get a "attempt to index ? (a number value)" error on line 4 whenever it gets called
I works if I keep string.len(ID) out of the function. what am I doing wrong :S
Edited by
Kingdaro #2
Posted 12 February 2013 - 03:29 AM
Rename your "string" variable to something else. You're overwriting a global API.
Zorach #3
Posted 12 February 2013 - 01:06 PM
ah TYVM I feel very foolish