• How to read variables off a text file?
    7 replies, posted
How can I read a variable off a text file? Just like make console say it, what do I need to do? What needs to be put in the .txt file and what needs to be put in the .lua files.
Depends on how you want to format it. Reading the contents of a file is very easy, just do filecontents = file.Read("somefile.txt") and it'll dump the whole contents in string form. Then you parse all that to give you the wanted values. Another method is to use a builtin method of formatting data in the text files, util.TableToKeyValues and util.KeyValuesToTable. The former will take any table and convert it into a string you can store in a text file, and the latter will take a string and process it to give you the table back. [URL]http://wiki.garrysmod.com/?title=Util.TableToKeyValues[/URL] [URL]http://wiki.garrysmod.com/?title=Util.KeyValuesToTable[/URL] Apparently GLON does much the same thing but is much more efficient. [url]http://wiki.garrysmod.com/?title=Glon.encode[/url] [url]http://wiki.garrysmod.com/?title=Glon.decode[/url] Both are essentially methods of turning Lua tables into text-file-friendly string data and back again.
Okay thanks, but when you make files like that, can't anyone edit them thats in the server?
Not at all. If a clientside script calls some file operation functions it'll just read/write files on the client computer.
Okay. Also, are there any tuts for setting up a mysql database for gmod. Like that PERP and Darkland use?
GMod has an SQL database for you to use builtin. It actually has two, one for the server and one for the client. Which one is manipulated depends on what the code was run on. [url]http://wiki.garrysmod.com/?title=Sql[/url]
That is for SQ Lite. I want one that I can actually look at the database.
I'm not sure about tutorials, but there is a binary DLL that adds functions to interface with an existing MySQL database in GMod Lua. [url]http://www.facepunch.com/showthread.php?t=241247[/url]
Sorry, you need to Log In to post a reply to this thread.