[Solved] writing to file with Lua

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
cndr
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 65
Joined: Sat Apr 24, 2010 7:03 am
Programming Language of Choice: etc.

[Solved] writing to file with Lua

Post by cndr »

I am attempting to learn lua, can't find too many tutorials online, but I would like to write to a file

Code: Select all

io.write("What is your age: ")
age = io.read() 
print ("You are " .. age .. " years old"); --now I would like to write this line to a file, how would I go about doing this?
Last edited by cndr on Sat Apr 24, 2010 10:07 pm, edited 1 time in total.
Long Live The Queen!
User avatar
GroundUpEngine
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 835
Joined: Sun Nov 08, 2009 2:01 pm
Current Project: mixture
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Location: UK

Re: writing to file with Lua

Post by GroundUpEngine »

Something like this I think, my Lua is rusty as hell though :lol:

Code: Select all

file = io.open("Age.txt","w") --"w" is Overwrite and "a" is Append
file:write(age)
file:close()
User avatar
cndr
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 65
Joined: Sat Apr 24, 2010 7:03 am
Programming Language of Choice: etc.

Re: [Solved] writing to file with Lua

Post by cndr »

worked perfectly thanks for the help!
Long Live The Queen!
User avatar
GroundUpEngine
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 835
Joined: Sun Nov 08, 2009 2:01 pm
Current Project: mixture
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Location: UK

Re: [Solved] writing to file with Lua

Post by GroundUpEngine »

cndr wrote:worked perfectly thanks for the help!
No Prob, hmm I might start using Lua again! :D
Post Reply