Lua save string to file

I've started using Lua for school, and I'm wondering if it is possible to save a string to a txt file?

i.e

I have a string called shroom and it equals mush.

I have a file in the same folder as the .lua file called output.txt.

I now want to save the string shroom to output.txt.

I then want to make a while loop and every 1 second save the string shroom to the output.txt file, overwriting the contents of output.txt each time i save the string.

Is this possible in Lua? I've never used Lua before and I'm really confused at the moment..

Thanks :)

3

1 Answer

You can read this chapter from Programming in Lua to see how you can work with files; you'll need to use "w" mode when you open file and then call f:write(shroom) to do the write.

For sleeping in a loop you may want to check suggestions in this SO question.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like