Jump to content




Writing a key to a file


  • You cannot reply to this topic
3 replies to this topic

#1 _removed

  • Members
  • 262 posts

Posted 14 April 2015 - 02:45 PM

My new project is related to tables. I have a setup like this:

{
  Title = {
    ...
  }
}

I want to add a new key to it, like this:

{
  Title = {
    ...
  },

  NewKey = {
   ...
  }
}

How would I achieve this?

#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 14 April 2015 - 02:46 PM

1. Open file
2. Read file
3. Unserialize to table
4. Add key
5. Serialize new table
6. Write serialized table to file


#3 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 14 April 2015 - 02:47 PM

Lets say your table is named tbl, and inside of it is contained the table named Title, then to create the table named NewKey you would only have to do this:
local tbl = {Title = {} }
tbl["NewKey"] = {}
--#Or
tbl.NewKey = {} --#Can only do this for constant names.

Edit: I'm not certain if this is considered being ninja'd, since we're not entirely talking about the same thing. Yami is on the bigger picture if you're talking about tables in a file, but this is how to do it with a normal table. Although the title of the thread IS "writing key to a file" Yami is correct on the way to go, you must read, edit, then replace the file.

Edited by Dragon53535, 14 April 2015 - 02:49 PM.


#4 _removed

  • Members
  • 262 posts

Posted 14 April 2015 - 02:53 PM

View PostDragon53535, on 14 April 2015 - 02:47 PM, said:

Lets say your table is named tbl, and inside of it is contained the table named Title, then to create the table named NewKey you would only have to do this:
local tbl = {Title = {} }
tbl["NewKey"] = {}
--#Or
tbl.NewKey = {} --#Can only do this for constant names.

Edit: I'm not certain if this is considered being ninja'd, since we're not entirely talking about the same thing. Yami is on the bigger picture if you're talking about tables in a file, but this is how to do it with a normal table. Although the title of the thread IS "writing key to a file" Yami is correct on the way to go, you must read, edit, then replace the file.

Yeah, It was to do with a file.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users