luacomputercraft

Is there a possiblity to create a variable with a string for everything inside of a table?


Just wondering about that, because i don't find a solution for it. Pretty sure because I'm new to this c: Thanks for your help.

Edit: for explanation im gonna explain it with the code a bit.

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

Solution

  • LIKE this?

    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