How to write inside files

All about writing scripts for Celestia in Lua and the .cel system
Topic author
rinoa79
Posts: 42
Joined: 20.11.2007
Age: 45
With us: 17 years
Location: Milan, Italy

How to write inside files

Post #1by rinoa79 » 13.09.2008, 21:04

Hi,
I'm learning to write files via celestia with the "io.open()"
using the function that is on page
viewtopic.php?f=9&t=8326 but nothing happens.
He says that Celestia wrote the file but there isn't anything in the file. 8O
I can not understand what is wrong... :?:
Someone can help me?
Thanks in advance!

Avatar
selden
Developer
Posts: 10192
Joined: 04.09.2002
With us: 22 years 3 months
Location: NY, USA

Re: How to write inside files

Post #2by selden » 14.09.2008, 11:37

It works fine for me under Windows XP SP3 using Celestia v1.5.1.

Here's the minimal example code, leaving out the on-screen display and writing to Celestia's extras directory

Code: Select all

celestia:requestsystemaccess()
myfile = io.open("extras/test.txt","w")

text = "Hello, Universe!"
myfile:write(text)
myfile:close()


First it asks if you want to allow I/O operations.
Then the file text.txt is created in Celestia's extras folder on my computer. It contains the string
Hello, Universe!
Selden

Topic author
rinoa79
Posts: 42
Joined: 20.11.2007
Age: 45
With us: 17 years
Location: Milan, Italy

Re: How to write inside files

Post #3by rinoa79 » 14.09.2008, 11:52

selden wrote:It works fine for me under Windows XP SP3 using Celestia v1.5.1.

Here's the minimal example code, leaving out the on-screen display and writing to Celestia's extras directory

Code: Select all

celestia:requestsystemaccess()
myfile = io.open("extras/test.txt","w")

text = "Hello, Universe!"
myfile:write(text)
myfile:close()


First it asks if you want to allow I/O operations.
Then the file text.txt is created in Celestia's extras folder on my computer. It contains the string
Hello, Universe!


Your code works. I don't know why the other not!
I'm starting to yours!
thank you very much!
:D


Return to “Scripting”