title: Attempt to index field '?' (a nil value) - error
body: <p>I can't figure out what is wrong with my code but what I'm trying to achieve is to have regular spawns of blocks scroll past the screen which the player has to dodge. when each block goes off the left hand side of the screen, it increases the 'obstacle values +1' </p>
  
  <p>The problem I have is that when my 'block' object goes off screen I get this error: </p>
  
  <p>"Attempt to index field '?' (a nil value)" </p>
  
  <p>can anyone help me because I really am stuck. 
  thanks </p>
  
  <pre><code>local yPos = {50,110,200}
  local speed = 6
  local block = {}
  local obstacles = 0
  
  
  function createBlock(event)
    local rnd = math.floor(math.random() * 4) + 1
    b = display.newImage('images/block3.png', display.contentWidth, yPos[math.floor(math.random() * 3)+1])
    b.x = 480
    b.name = 'block'
    physics.addBody(b, "static")
    blocks:insert(b)
    print(b.x)
  
    return true
  
  end
  
  function gameLoop( event )
     if(blocks ~= nil)then
       for i = 1, blocks.numChildren do
        blocks[i].x = blocks[i].x - speed -- (( THIS IS THE LINE WHICH GENERATES THE ERROR))
         if(blocks[i].x &lt; -0) then
           display.remove(blocks[i])
           blocks[i] = nil
           print("+1!!")
           obstacles = obstacles +1
         end
       end 
    end
  end
  
  
  timerSrc = timer.performWithDelay(900, createBlock, 0)
  Runtime:addEventListener("enterFrame", gameLoop)
  </code></pre>