使用ComputerCraft进行Lua编程
2014-3-9 17:42:18
收藏:0
阅读:99
评论:1
我创建了一个小程序,询问您想要一个挖掘乌龟挖掘的长度、宽度和高度。当我在高级计算机上运行它时,它让我提示长度、宽度和高度,但是我会遇到一个错误。错误如下:
miner:39: attempt to index ? ( a nil value)
以下是我的代码:
term.clear()
term.setCursorPos(1,1)
write("Length:")
length = read()
print()
write("Confirm:")
ul = read()
print()
write("Width:")
width = read()
print()
write("Confirm:")
uw = read()
print()
write("Height:")
height = read()
print()
write("Confirm:")
uh = read()
print()
local totcount = ul + uw + uh
local subcount = 0
function Length()
repeat
turtle.dig()
turtle.forward()
length = length - 1
subcount = subcount + 1
until length == 0
length = ul
end
function Width()
repeat
turtle.dig()
turtle.forward()
width = width - 1
subcount = subcount + 1
until width == 0
width = uw
end
function Height()
turtle.digDown()
turtle.down()
height = height - 1
subcount = subcount + 1
end
function Turn()
turtle.turnRight()
end
repeat
Length()
Turn()
Width()
Turn()
Length()
Turn()
Width()
Turn()
Height()
until subcount == totcount
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- 如何将两个不同的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中获取用户配置主目录的跨平台方法
将下面翻译成中文并且保留原本的 markdown 格式
It doesn't look any of your functions have `end`, fix that first. If you properly indent your code you will see this. You also have `while count < length do` with an `else` block. AFAIK this is not valid syntax (never seen it and just checked online ref manual and wiki). It is not clear whether you meant `if count < length do`, but if really meant `while` then replacing `else` by `end` doesn't look right either. Take a closer look at that section of code.看起来你的函数都没有使用
end,先修正这个问题。如果你正确缩进你的代码,你就能看到这个错误。你的代码中还有一个
while count < length do循环,它带有一个else代码块。据我所知,这不是有效的语法(我从未见过这种用法,刚刚查询了一下在线的标准手册和维基百科)。不清楚你是否想使用if count < length do,但如果你真想使用while循环,那么将else替换为end也不是恰当的做法。请仔细检查那个代码段。