Lua saves the string to the file

I started to use Lua to go to school, I want to know if it is possible to save the string to a txt file?

That is

I have a string called shroom, which is equal to mushy.

I am in the folder where the .lua file is located There is a file named output.txt.

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

Then I want to make a while loop, which will The string shroom is saved to the output.txt file, and the content of output.txt will be overwritten every time the string is saved.

Is it possible for Lua? I have never used Lua before, and I am really confused at the moment.

Thank you:)

You can read this chapter from Programming in Lua to learn how to use the file; when you open the file and then call f:write(shroom) to write, you need to use the “w” mode.

For sleeping in a loop, you may need to see the suggestions in this SO question.

I started to use Lua to go to school, I want to know if Can the string be saved to a txt file?

That is

I have a string called shroom, which is equal to mushy.

I am in the folder where the .lua file is located There is a file named output.txt.

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

Then I want to make a while loop, which will The string shroom is saved to the output.txt file, and the content of output.txt will be overwritten every time the string is saved.

Is it possible for Lua? I have never used Lua before, and I am really confused at the moment.

Thank you:)

You can use the Programming in Lua Read this chapter in this chapter to learn how to use files; when you open the file and then call f:write(shroom) for writing, you need to use the “w” mode.

For in the loop Sleep, you may need to see the suggestions in this SO question.

Leave a Comment

Your email address will not be published.