0

我正在尝试学习如何对 Computercraft Mining Turtles 进行编程,并且我想编写一个程序,提示用户输入立方体的边长尺寸,然后构建该立方体。我使用 io.read() 让用户输入边长,以及他希望立方体通过 Y/N 输入是实心的还是空心的。但是,当我检查最后一个问题的答案时,我得到一个错误,我有一个表并且需要一个字符串。错误代码:多维数据集:17:错误参数:预期字符串,得到表

这是我的代码

--"Cube constructor"
--"Powered by UglySoft"

function get_dimensions()
  --"prompts for cube dimensions and Solid"

  print("Please enter the Cube dimensions.\n")

  io.write("Cube side length ")
  side_length = tonumber(io.read())

  io.write("Solid Cube? (Y/N) ")
  solid = io.read()


  solid = string:lower()

  return side_length, solid
end

function build_solid(side_length)
    print("Building solid Cube with side length ", side_length)
end

function build_hollow(side_length)
    print("Building hollow Cube with side length ", side_length)
end


function main()
    --"main part of the program"
    term.clear()
    print("Welcome to Cube Builder")
    print("powered by UglySoft \n")


    get_dimensions()

    if solid == "y" then
        build_solid()
    else
        build_hollow()
    end

end


main()

我对 lua 很陌生,我什至不确定在这种情况下是否应该使用 io.read() 。非常感谢任何帮助,并随时提出问题。

4

2 回答 2

1

你的问题是string:lower()哪些去糖string.lower(string)尝试在string桌子上操作。那是行不通的。

你想要solid:lower()string.lower(solid)

于 2015-08-28T14:32:28.937 回答
0

在 ComputerCraft 中,您通常应该使用内置函数

read()

而不是io.read因为io.read用于读取文件而不是用户输入。

io.write您也可以使用writeor代替print

于 2017-10-26T20:59:52.253 回答