lua - Lua:“:40:'}'预计(在'='附近关闭'{'在第37行)”
问题描述
错误提示我缺少 },但我正在关闭 {}。我正在使用 Lua 和 TIC-80 编写 2D 游戏。我一直在尝试解决这个问题,但我不知道这里有什么问题。谁能帮帮我吗?该错误表明问题出在“inferiorRight”对象中,并且我没有关闭“{”
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
解决方案
这不是player.y
用作表键的正确语法:
inferiorRight = {
x = player.x + 7,
y = player.y + 7,
player.y = player.y + 7 + myDisplacementY --<--
}
如果您确实想拥有player.y
作为密钥,则需要将其写为["player.y"]
.
推荐阅读
- android - Textview ellipsize 文本不带点并剪切最后一个单词
- r - 在R中删除双图例
- modelica - 如何在 Dymola 中安装新的 Modelica 库?
- webview - 服务器离线时android apk的webview错误问题
- linux-kernel - Google Coral SoM 上的 1-Wire 通信
- java - Angular-Springboot 无法将我的 File 属性映射到我的 MultipartFile 属性
- amazon-web-services - 如何使用 Flutter 使用现有的 aws s3 Bucket
- snowflake-cloud-data-platform - 如何从雪花生成固定宽度的文件并卸载到内部阶段
- java - 如何使用 BigDecimal 正确计算有理数
- html - 辅助功能:如何配置“列标题”公告?