Page 1 of 1

A couple of Celx PRINT functions

Posted: 18.04.2004, 09:21
by don
.
[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!

Posted: 18.04.2004, 14:54
by marc
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.

Posted: 18.04.2004, 19:47
by don
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...

Posted: 19.04.2004, 03:52
by Toti
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 :)

Posted: 19.04.2004, 04:26
by don
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. :)

Posted: 19.04.2004, 04:35
by don
.
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)