Jump to content

Get a table from a .txt file


Recommended Posts

Posted

Hey dear community,

Im just looking for a way if I can get a table with a lot of values to add it on an script

I don't know if you understand me, then I will explain it better.

-- TXT Files (test.txt)

thisIsMyTable = {"value1","value2","value3","value4","value5"}

otherTable = {"value1","value2","value3","value4","value5"}

later I would like to load it on my script

  
local variableScript = {} 
local otherVariableScript = {} 
  
function getTheVariables(table1,table2) 
    if table1 then 
        variableScript = table1 
    end 
    if table2 then 
        otherVariableScript = table2 
    end 
end 
  

Thanks for reading.

Regards.

Posted

You could get the content of a .txt file with the io library. But I just don't get why you're trying to do it like that when there are more simplified ways to do it.

"Keep making it simplex."

  • Moderators
Posted

local myContent = {

thisIsMyTable = {"value1","value2","value3","value4","value5"},

otherTable = {"value1","value2","value3","value4","value5"}

}

Read it and loadstring. As simple as that.

Yet, why aren't you just use a lua file? And more important, what is the endresult?

Or use only XML, which is in my opinion much more flexible and easy to use.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...