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

All about writing scripts for Celestia in Lua and the .cel system
Avatar
Topic author
parduz
Posts: 26
Joined: 21.04.2003
With us: 21 years 6 months
Location: Bologna (Italy)

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

Post #1by parduz » 16.11.2017, 19:13

Hello.

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?

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

Post #2by selden » 16.11.2017, 20:13

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 https://en.wikibooks.org/wiki/Celestia/Celx_Scrip ... x_celestia#requestsystemaccess
Selden

Janus
Posts: 537
Joined: 13.08.2016
With us: 8 years 2 months

Post #3by Janus » 16.11.2017, 22:23

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.


Janus.

Avatar
Topic author
parduz
Posts: 26
Joined: 21.04.2003
With us: 21 years 6 months
Location: Bologna (Italy)

Post #4by parduz » 17.11.2017, 09:16

Thanks selden.

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

Avatar
Chuft-Captain
Posts: 1779
Joined: 18.12.2005
With us: 18 years 10 months

Post #5by Chuft-Captain » 17.11.2017, 12:37

Parduz,

This works in Windows.

CC
Last edited by Chuft-Captain on 20.11.2017, 01:12, edited 1 time in total.
"Is a planetary surface the right place for an expanding technological civilization?"
-- Gerard K. O'Neill (1969)

CATALOG SYNTAX HIGHLIGHTING TOOLS LAGRANGE POINTS

Janus
Posts: 537
Joined: 13.08.2016
With us: 8 years 2 months

Post #6by Janus » 17.11.2017, 15:38

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.


Janus.

Avatar
Topic author
parduz
Posts: 26
Joined: 21.04.2003
With us: 21 years 6 months
Location: Bologna (Italy)

Post #7by parduz » 17.11.2017, 15:47

This is so great!
Thanks!

Avatar
Chuft-Captain
Posts: 1779
Joined: 18.12.2005
With us: 18 years 10 months

Post #8by Chuft-Captain » 17.11.2017, 19:35

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.

CC
"Is a planetary surface the right place for an expanding technological civilization?"
-- Gerard K. O'Neill (1969)

CATALOG SYNTAX HIGHLIGHTING TOOLS LAGRANGE POINTS


Return to “Scripting”