首页 > 解决方案 > 是否有可能为表内的所有内容创建一个带有字符串的变量?

问题描述

只是想知道,因为我没有找到解决方案。很确定,因为我是这个 c 的新手:感谢您的帮助。

编辑:为了解释,我会用代码解释一下。

local FileList = fs.list("") --Makes a Table with all the files and directories available (as strings) on the PC it's running on (Inside of a mod called computercraft for minecraft)

for _, file in ipairs(FileList) do 
    --Here I need a function which assigns every string from the table to a variable, just for the explanation I'll call it unknown.function
   
    unknown.function
end 

while true do
    print(a) --a is for example one of the different variables made from the "unknown.function" 
    sleep(1)
end

标签: luacomputercraft

解决方案


像这样?

AllFiles = {}

function Crazyfunction(file)

 AllFiles[table.getn(AllFiles)+1] = file
 
end

local FileList = fs.list("")

for _, file in ipairs(FileList) do 
    Crazyfunction(file)
end 

while true do
    print(AllFiles[NUMBE_OF_FILE_HERE])
    sleep(1)
end

推荐阅读