lua (love2d): function supposedly missing an end
2021-10-2 5:56:1
收藏:0
阅读:146
评论:1
它说第 98 行的函数缺少一个 end
。我发誓没有缺少 end
,我一遍一遍地检查,也找不到问题所在。
错误
语法错误:main.lua:142: 需要 'end'(在第 98 行关闭 'function')附近''
回溯
[C] 中的 0x07f9a11328f0 中的 'require' 函数 [C] 中的 'xpcall' 函数 [C] 中的 'xpcall' 函数
player = {}
opponent = {}
ball = {}
screen ={}
function love.load()
screen.top = 0
screen.bottom = love.graphics.getHeight()
screen.left = 0
screen.right = love.graphics.getWidth()
player.x = 50
player.y = screen.bottom / 2
player.width = 20
player.height = 100
player.speed = 500
opponent.x = screen.right - 50
opponent.y = screen.bottom / 2
opponent.width = 20
opponent.height = 100
opponent.speed = 400
ball.x = screen.right / 2 - 10
ball.y = screen.bottom / 2 - 10
ball.width = 20
ball.height = 20
ball.speed = 200
ball.xVel = -ball.speed
ball.yVel = 0
end
function love.update(dt)
player.move(dt)
opponent.move(dt)
ball.move(dt)
ball.collide(dt)
end
function love.draw(dt)
player.draw()
opponent.draw()
ball.draw()
end
function checkCollision(a, b)
if a.x + a.width > b.x and a.x < b.x + b.width and a.y + a.height > b.y and a.y < b.y + b.height then
return true
else
return false
end
end
function player.draw()
love.graphics.rectangle('fill', player.x, player.y, player.width, player.height)
end
function player.move(dt)
if love.keyboard.isDown('w') then
player.y = player.y - player.speed * dt
elseif love.keyboard.isDown('s') then
player.y = player.y + player.speed * dt
end
if player.y < screen.top then
player.y = screen.top
elseif player.y + player.height > screen.bottom then
player.y = screen.bottom - player.height
end
end
function opponent.draw()
love.graphics.rectangle('fill', opponent.x, opponent.y, opponent.width, opponent.height)
end
function opponent.move(dt)
if ball.y + ball.height < opponent.y then
opponent.y = opponent.y - opponent.speed
else if ball.y > opponent.y + opponent.height then
opponent.y = opponent.y + opponent.speed
end
if opponent.y < screen.top then
opponent.y = screen.top
elseif opponent.y + opponent.height > screen.bottom then
opponent.y = screen.bottom - opponent.height
end
end
function ball.draw()
love.graphics.rectangle('fill', ball.x, ball.y, ball.width, ball.height)
end
function ball.move(dt)
ball.x = ball.x + ball.xVel * dt
ball.y = ball.y + ball.yVel * dt
if ball.y < screen.top then
ball.y = screen.top
ball.yVel = -ball.yVel
elseif ball.y + ball.height > screen.bottom then
ball.y = screen.bottom
ball.yVel = -ball.yVel
end
end
function ball.collide(dt)
if checkCollision(ball, player) then
ball.xVel = -ball.xVel
local middleBall = ball.y + (ball.height / 2)
local middlePlayer = player.y + (player.height / 2)
local collisionPosition = middleBall - middlePlayer
ball.yVel = collisionPosition
end
end
原文链接 https://stackoverflow.com/questions/69414379
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?
- addEventListener 返回 nil Lua
- Lua中获取用户配置主目录的跨平台方法
- 如何编写 Lua 模式将字符串(嵌套数组)转换为真正的数组?
我把它粘贴到带有语法高亮的
vi
中,一眼看到opponent.move(dt)
需要一个蓝色的end
来关闭该函数块。但是我不想决定缺少的
end
属于哪个if
来更正它。哎呀,现在我看到了。
你用的是“else if”,而不是“elseif”。