user10087137
user10087137

Reputation:

LUA Write contents of file to another (Garry's Mod)

local myvariable = print( file.Read( "dir1/file1.txt" ) )
file.Write( "dir2/file2.txt", "myvariable" )

This code will only write "myvariable" to file2.txt but I want the contents from file1.txt to be written to file2.txt. Can I make a "string" be read as a variable? Any other ideas to make this work?

Note: This is for Garry's Mod so its LUA can be referenced here: http://wiki.garrysmod.com/page/Main_Page

Upvotes: 1

Views: 970

Answers (2)

user10087137
user10087137

Reputation:

I found out that LUA can use really long strings, so I put all the text in the script, rather than in a file of its own.

The cl.lua file has the client read the file and displays the text as desired (in my case it opened in a box i.e. vgui.Create("DFrame")):

    ...
    text:SetText(file.Read("dir/to/large_text_file.txt", "DATA"))
    ...

In the .lua file that actually writes the giant string to the file that (as previously mentioned) is read:

...
file.Write( "dir/to/large_text_file.txt", "really long string that is written to said file... this string ended up over 10,000 characters for me" )

Upvotes: 0

lhf
lhf

Reputation: 72402

Try

local myvariable = file.Read( "dir1/file1.txt" )
file.Write( "dir2/file2.txt", myvariable )

Upvotes: 2

Related Questions