Page 1 of 1

cel script: Is it possible to print text from another file using index?

Posted: 16.11.2017, 19:13
by parduz

I'll have to help a kid writing "a lesson" (a detailed Solar system tour) using Celestia. He will write all the text, i'll do all the programming/scripting part.
It could be much easier if he could write whatever it wants on a file (call it "lesson.txt"), and (using a bit of formatting?) print that lines of text from the "Showlesson.cel" file... using arrays and indexes?

i tried to look about this but i have'nt found nothing.

Is it possible? If yes, how?

Posted: 16.11.2017, 20:13
by selden
You'll have to write a .CELX script, not a .CEL script. Then you can use standard Lua I/O calls. They're not specific to Celestia. However, you do have to ask Celestia to let you do it. By default, file I/O is not allowed.

See ... x_celestia#requestsystemaccess

Posted: 16.11.2017, 22:23
by Janus
Years ago when I did the first pre alpha versions of my solar system tour DVD, I used a system like that.
This was quite a few years ago and my notes are non existent, this is just off the top of my head.

What I did was make a file that created an associative table in a file such as planetinfo.celx for instance.

Planet_Table = {}
Planet_Table["Mercury"] = "This is Mercury, the first and fastest planet. It goes around the sun in 88 of our days, which is its year."
Planet_Table["Venus"] = "This is Venus, the brightest planet in our sky, better known the dawn or evening star."

Then 'require' that associative array in my main script.

local PlanetTable = require("planetinfo.celx.Planet_Table")

Then call celestia:print(PlanetTable['Mercury'])

I don't remember exactly, but it was something like this.
The planetinfo.celx had a return or something in it I think.
It was funky and awkward, but worked.
If I can find it again, I can post it if needed.


Posted: 17.11.2017, 09:16
by parduz
Thanks selden.

If I can find it again, I can post it if needed.
i'd like to see it, in that case!

Posted: 17.11.2017, 12:37
by Chuft-Captain

This works in Windows.


Posted: 17.11.2017, 15:38
by Janus
It would appear that Chuft-Captain has outdone the very minor successes I achieved way back when.
Congratulations by the way, it is nice to see.

Better results than I ever got, and nicely done.


Posted: 17.11.2017, 15:47
by parduz
This is so great!

Posted: 17.11.2017, 19:35
by Chuft-Captain
You're welcome,

In theory, this should have been some pretty standard lua/Celx scripting, but I struggled for a few hours trying to get the script to recognize the LUA file.
I do like a challenge, but this turned out to be more difficult than I expected, and seemingly intractable. Luckily I discovered that this exact issue had been identified (and solved) by Selden and Hank over 10 years ago.