0
votes

The error says i'm missing a } but i'm closing the {}. I'm coding a 2D game using Lua and TIC-80. I've been trying to solve this issue but I don't have any ideia of what is the problem here. Can anyone please help me? The error says that the problem is in the "inferiorRight" object and that I'm not closing the '{'

function tryToMoveTo(myDisplacementY)
    superiorLeft = {
        x = player.x - 8,
        y = player.y - 8 - 1
    }
    superiorRight = {
        x = player.x + 4,
        y = player.y - 8 - 1
    }
    inferiorRight = {
        x = player.x + 7,
        y = player.y + 7,
        player.y = player.y + 7 + myDisplacementY
    }
    inferiorLeft = {
        x = player.x - 8,
        y = player.y + 7 + myDisplacementY
    }
        
    if collidesWithMap(inferiorRight) or
     collidesWithMap(inferiorLeft) or
        collidesWithMap(superiorRight) or
        collidesWithMap(superiorRight) then
     -- collides
    else
        player.y = player.y + myDisplacementY
    end
end

function update()
    -- up
    if btn(0) then
      tryToMoveTo(-1)
    end
    -- down
    if btn(1) then
      tryToMoveTo(1)                
    end
    -- left
    if btn(2) then
      player.x = player.x - 1
    end
    -- right
    if btn(3) then
      player.x = player.x + 1
    end
end
1
error in index name in string: player.y = player.y + 7 + myDisplacementY - Mike V.

1 Answers

1
votes

This is not a proper syntax with player.y used as a table key:

inferiorRight = {
    x = player.x + 7,
    y = player.y + 7,
    player.y = player.y + 7 + myDisplacementY --<--
}

If you indeed want to have player.y as the key, you need to write it as ["player.y"].