• How to load .txt data into Lua?
    8 replies, posted
Pretty much, I'm making a gamemode and I want to load .txt data into the gamemode. How would I achieve this? One way that my friend did this was by runstring'ing the stuff read from a text file which had a bunch of tables in Lua format, but that seems a bit hacky and unsafe. Is there a better way? Should I even use .txt files to do this and instead, just define all the data in a .lua file or something? Any help or useful input is appreciated.
[code]local tbl = {} function SaveData() file.Write("gamemodedata.txt",util.TableToJSON(tbl)) -- save the table as a text file end function LoadData() tbl = util.JSONToTable(file.Read("gamemodedata.txt", "DATA")) -- load the table. end LoadData() -- call LoadData() to load the data for the first time[/code] Though it's better to use MySQL/SQLite
What kind of data? Config? Use Lua.
[QUOTE=Robotboy655;44245414]What kind of data? Config? Use Lua.[/QUOTE] Oh shoot, forgot to mention, sorry. It's stuff like map data, aka spawnpoints of entities, etc. So pretty much config I guess. What would using Lua offer over a .txt though? Other than making it easier to do stuff I guess, and maybe speed.
[QUOTE=awcmon;44247436]Oh shoot, forgot to mention, sorry. It's stuff like map data, aka spawnpoints of entities, etc. So pretty much config I guess. What would using Lua offer over a .txt though? Other than making it easier to do stuff I guess, and maybe speed.[/QUOTE] Use .lua files.
Put it this way, no matter whether it's txt or lua they will both require the modder to follow a format. I don't see any advantages of txt files.
rename your thing (Yes, I know I didn't use grammar) example: yourbitch.lua.txt then it should go into the txt format
[QUOTE=Tinynick916;44248069]rename your thing (Yes, I know I didn't use grammar) example: yourbitch.lua.txt then it should go into the txt format[/QUOTE] Ok, so like this? [code]Tinynick916.lua.txt[/code] I think I got it right, now what?
[QUOTE=Tinynick916;44248069]rename your thing (Yes, I know I didn't use grammar) example: yourbitch.lua.txt then it should go into the txt format[/QUOTE] .... no ......
Sorry, you need to Log In to post a reply to this thread.