Lua代码错误(我是新手)
2016-1-17 20:6:38
收藏:0
阅读:84
评论:4
这段代码有什么问题?
if key == 'w' then
if charastate == neutral then
charamov = up
end
elseif charastate == lr then
charastate = neutral then
charamov = up
end
end
错误是:
"unexpected symbol near 'then'"
同时,即使更改为 "and",也没有影响。
谢谢,我正在试图自学,但是非常劳累。
点赞
用户4019159
尝试一下这段代码。在else if语句中使用了两个then。
如果`key`等于`w`,则
如果`charastate`等于`neutral`,则
`charamov`等于`up`
否则如果`charastate`等于`lr`,则
`charastate`等于`neutral`
`charamov`等于`up`
结束
end
2016-01-17 19:39:38
用户5799596
我认为你在这里缺少一个 if 语句:
elseif charastate == lr then
charastate = neutral then
charamov = up
end
我建议你使用 and 运算符而非嵌套你的 if 语句,这样可以更容易地编辑和阅读代码:
if key == 'w' and charastate == neutral then
charamov = up
elseif key == 'w' and charastate == lr then
charamov = up
end
2016-01-17 20:51:43
用户3125367
为了帮助理解原始代码存在的问题,我对相应部分进行了注释,因此:
if key == 'w' then
if charastate == neutral then
charamov = up
--[[ end BAD(1) ]]
elseif charastate == lr then
charastate = neutral --[[ then BAD(2) ]]
charamov = up
end
end
两个问题都是语法上的。1)if-elseif语句的形式为if <cond> then <statements> [elseif <statements>]+ end。请注意,在elseif之前没有end。2)then关键字不适用。原始代码在正确缩进后如下所示:
if key == 'w' then
if charastate == neutral then
charamov = up
end
elseif charastate == lr then
charastate = neutral then -- 这是语法错误
charamov = up
end
end -- 这个end是多余的,但解析器甚至无法到达这里
(对于程序逻辑几乎没有任何意义。)
2016-01-18 08:58:25
评论区的留言会收到邮件通知哦~
推荐文章
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在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中获取用户配置主目录的跨平台方法
错误提示告诉你要省略最后一个
then,因为它没有与if对应。正确缩进代码将有助于你看到它。