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

Tetris

Started by bobmandude9889, 08 December 2013 - 11:32 PM
bobmandude9889 #1
Posted 09 December 2013 - 12:32 AM
Ive been trying to make tetris for the past few days and I keep getting this error


tetris:264:	attempt to index ? (a nil value)

It happens after 3 or 4 blocks fall!

Here is the code:
http://pastebin.com/emAYWn2m

And make sure you have the paintutils image file:
pastebin get BqsWs3DY tetris_files/board_outline

Thank You so much!
Bomb Bloke #2
Posted 09 December 2013 - 01:57 AM
Near the end of the line is this expression:

layer[a+1]:sub(b,b) ~= "x"

Should just be "layer[a]".

Edit: Waaait a second, then it matches the first expression in the line…

The crash is specifically complaining because you're attempting to pull a substring of a string that doesn't exist. Luckily Lua is bright enough not to resolve entire conditionals once it gets to a point where it knows what the answer is going to be, hence you can do this:

elseif layer[a]:sub(b,b) == "x" and board[y+a]:sub(x+b-1,x+b-1) == "x" and (a==height or layer[a+1]:sub(b,b) ~= "x") then
Edited on 09 December 2013 - 01:12 AM