A couple of Celx PRINT functions

All about writing scripts for Celestia in Lua and the .cel system
Topic author
don
Posts: 1709
Joined: 12.07.2003
With us: 21 years 4 months
Location: Colorado, USA (7000 ft)

A couple of Celx PRINT functions

Post #1by don » 18.04.2004, 09:21

.
[April 18, 2004 ... Updated to version 1.1: Changed printTime to displayTime. Just seems better.]


Don G's Celx PRINT functions for Celestia (Version 1.1)

The script code: (http://www.donandcarla.com/Celestia/celx_scripting/PrintFunctions_1-1.celx.txt)
My Celestia page: (http://www.donandcarla.com/Celestia/)

The code in this Celx script provides easy-to-use print functions that you can use in your own Celx scripts, and is provided FREE with NO STRINGS ATTACHED by Don G. The print functions include:

displayTime
...Determine the number of seconds to display text, based on the SEC_PER_CHAR global variable.

textWrap
...Determines where line feeds need to be inserted, based on the CHARS_PER_LINE global variable, and inserts them.

printLL
...This print function does several things:
    * If seconds is not provided, determines how long the text should be displayed (in seconds).

    * Counts the number of lines of text to be displayed.

    * Counts up from the bottom of the display to determine what line to start printing on.

    * Print the text in the lower left-hand corner of the display, using the HORIZONTAL_OFFSET global variable to determine how many characters from the left edge of the display to begin at.
Simply enter the text you want to display and let the printLL function do everything else! Some examples...

Code: Select all

Use printLL and specify the duration yourself...

printLL("Hello, my name is Don.", 5)

Code: Select all

Use printLL without passing a duration value (the function will compute one on it's own), with user-specified line-breaks...

printLL("This is a line of text.\nThis is a second line of text.\nThis is a third line of text.")

Code: Select all

Use printLL and textWrap...

printLL( textWrap("This is a lot of text, to demonstrate the textWrap and printLL functions. Earth is the third 'rock' from the sun and has a lot of man-made satellites and space junk orbiting around it.") )

Code: Select all

Use displayTime only...

text = "This is a line of text.\nThis is a second line of text.\nThis is a third line of text."
seconds = displayTime(text)
celestia:print(text, seconds, -1, -1, 0, 10)
wait(seconds)

Code: Select all

Use displayTime and textWrap...

myText = textWrap("This is a lot of text, to demonstrate the textWrap and printLL functions. Earth is the third 'rock' from the sun and has a lot of man-made satellites and space junk orbiting around it.")
seconds = displayTime(myText)
celestia:print(myText, seconds, -1, -1, 0, 10)
wait(seconds)


Enjoy!
Last edited by don on 21.04.2004, 06:26, edited 3 times in total.
-Don G.
My Celestia Scripting Resources page

Avatar: Total Lunar Eclipse from our back yard, Oct 2004. Panasonic FZ1 digital camera (no telescope), 36X digital zoom, 8 second exposure at f6.5.

marc
Posts: 426
Joined: 13.03.2002
With us: 22 years 8 months
Location: Outback Australia

Post #2by marc » 18.04.2004, 14:54

Excellent Don, it looks like we ave another lua expert. :wink:
I'm sure that the other script writers will find this useful, myself included.

Topic author
don
Posts: 1709
Joined: 12.07.2003
With us: 21 years 4 months
Location: Colorado, USA (7000 ft)

Post #3by don » 18.04.2004, 19:47

Hey Marc, thanks for your kind comments. I don't know about the "expert" part though. :lol:

I just like writing routines / functions that make languages easier to use. :D

More to come...
-Don G.

My Celestia Scripting Resources page



Avatar: Total Lunar Eclipse from our back yard, Oct 2004. Panasonic FZ1 digital camera (no telescope), 36X digital zoom, 8 second exposure at f6.5.

Toti
Developer
Posts: 338
Joined: 10.02.2004
With us: 20 years 9 months

Post #4by Toti » 19.04.2004, 03:52

Don:

Congratulations!

This will facilitate the creation of more informative, text-rich educational scripts. Just write the info text as a block and forget about the printing details: the computer will calculate how it should be formatted and the lapse that it will be showed on screen.

Again, excellent!
Bye :)

Topic author
don
Posts: 1709
Joined: 12.07.2003
With us: 21 years 4 months
Location: Colorado, USA (7000 ft)

Post #5by don » 19.04.2004, 04:26

Thank you Toti. After being side-tracked by the Sloan Digital Sky Survey database for a couple of weeks, I finally got this put together last night.

That's right, simply type in the text and let the built-in routines do the rest -- if you want the text displayed in the "typical" lower left-hand corner.

However, to do anything more complex, such as centering, or right-justification (as some languages are), would require access to font and window metrics (width, height, etc.) info, which is not available in Celestia's implementation of Lua. Maybe in time. :)
-Don G.

My Celestia Scripting Resources page



Avatar: Total Lunar Eclipse from our back yard, Oct 2004. Panasonic FZ1 digital camera (no telescope), 36X digital zoom, 8 second exposure at f6.5.

Topic author
don
Posts: 1709
Joined: 12.07.2003
With us: 21 years 4 months
Location: Colorado, USA (7000 ft)

Post #6by don » 19.04.2004, 04:35

.
April 18, 2004 ...

Just updated the file to version 1.1. Changed the function name printTime to displayTime. Just seems better.

The script code: (http://www.donandcarla.com/Celestia/celx_scripting/PrintFunctions_1-1.celx.txt)
-Don G.

My Celestia Scripting Resources page



Avatar: Total Lunar Eclipse from our back yard, Oct 2004. Panasonic FZ1 digital camera (no telescope), 36X digital zoom, 8 second exposure at f6.5.


Return to “Scripting”