This sections documents the classes (types of objects) available in
Lua-scripting. You can't create an object (i.e. an userdata) yourself,
you must call some method to create one. As you only have the
celestia-object (ignoring methods which are not Celestia related)
available when the script is starting, you must use it to create other
objects. For example, to call the method getposition() of observer, you
have to get an observer-instance from celestia first and then call
getposition on it:
Note that while I am using names for the various classes in this
documentation, these names have no real meaning in a script. Even
"celestia" is just a variable holding an object of type celestia and
not really special.
This is followed by a short description of what the method does, then a
list of the parameters and what they are for, and possibly some notes
about how to use this method, what it does exactly etc.
(back to index)This object is predefined
and gives access to all the celestia-related functionality available
for Lua-scripts, either directly by methods of celestia, or indirectly
by creating other objects which offer more functionality.
2.1.1. celestia:print(string:text [, number:duration, number:horig, number:vorig, number:hoffset, number:voffset])
Print text on screen
text:
A string containing the message to be printed. The string can contain
newlines "\n" to break lines, or many special characters encoded in
UTF-8.
duration [optional]: Number of seconds the text is shown. Default is 5.
horig [optional]: Horizontal origin of text, -1 is left, 0 center, 1 right
vorig [optional]: Vertical origin of text, -1 is bottom, 0 center, 1 top
hoffset [optional]: Offset relative to origin.
voffset [optional]: Offset relative to origin.
1.3.2
Celestia now supports UTF-8 strings as text.
2.1.2. celestia:flash(string:text [, number:duration])
Print text on screen, similar to print.
text:
A string containing the message to be printed. The string can contain
newlines "\n" to break lines, or many special characters encoded in
UTF-8.
duration [optional]: Number of seconds the text is shown. Default is 5.
1.3.2
Celestia now supports UTF-8 strings as text.
2.1.3. celestia:show(string:renderflag)
Enable one or many rendering features.
renderflag:
String describing the render-feature to be enabled. Must be one of
orbits, cloudmaps, constellations, galaxies, planets, stars, nightmaps,
eclipseshadows, ringshadows, comettails, boundaries, markers, automag,
atmospheres, grid, smoothlines 1.3.2
, lightdelay 1.3.2
, partialtrajectories 1.3.2
Multiple features can be enabled at once by giving multiple arguments to this method.
2.1.4. celestia:hide(string:renderflag)
Disable one or many rendering features.
renderflag: String describing the render-feature to be enabled. See celestia:show()
2.1.5. table celestia:getrenderflags()
1.3.2
Return a table with all known renderflags as keys, and a boolean as value indicating whether a specific renderflag is enabled.
2.1.6. celestia:setrenderflags(table:renderflags)
1.3.2
Enable or disable renderflags, i.e. enable/disable rendering of specific features.
renderflags: A table which contains the renderflags (see celestia:show()) as keys, and booleans as values for each key.
You can use show() and hide() or setrenderflags(), both have equivalent
functionality. The main reason for the existence of this method is as a
counterpart of getrenderflags(), e.g. to reset all renderflags to
values saved at the beginning of a script (for cleanup).
Example: enabling comet-tails and disabling nightmaps
t = {} -- create table
t.nightmaps = false
t.comettails = true
celestia:setrenderflags(t)
or shorter:
celestia:setrenderflags{nightmaps = false, comettails = true} -- note the curly braces
or old-style:
celestia:show("comettails")
celestia:hide("nightmaps")
2.1.7. celestia:showlabel(string:labelflag)
Enables labeling.
labelflag:
String describing the type of labels to enable, must be one of:
planets, moons, spacecraft, asteroids, comets, constellations, stars,
galaxies, locations1.3.2
Multiple features can be enabled at once by giving multiple arguments to this method.
2.1.8. celestia:hidelabel(string:labelflag)
Disable labeling.
labelflag: String describing the type of labels to disable. See celestia:showlabel().
2.1.9. table celestia:getlabelflags()
1.3.2
Return a table with all known labelflags as keys, and a boolean as
value indicating whether a specific labelflag is enabled. C.f.
getrenderflags().
2.1.10. celestia:setlabelflags(table:labelflags)
1.3.2
Enable or disable the rendering of labels.
labelflags: A table which contains the labelflags (see celestia:showlabels()) as keys, and booleans as values for each key.
See setrenderflags() for how to use this method.
2.1.11. table celestia:getorbitflags()
1.3.2
Return a table with all known orbitflags as keys, and a boolean as
value indicating whether a specific orbit is enabled. C.f.
getrenderflags().
2.1.12. celestia:setorbitflags(table:orbitflags)
1.3.2
Enable or disable the rendering of specific orbits.
orbitflags: A table which contains the orbitflags as keys, and booleans as values for each key.
Each orbitflag must be one of: Planet, Moon, Asteroid, Comet,
Spacecraft, Invisible, Unknown. See setrenderflags() for how to use
this method.
2.1.14. celestia:setambient(number:ambient)
1.3.2
Set the level of ambient light.
ambient: The new level of ambient light, must be between 0 and 1.
2.1.15. number celestia:getfaintestvisible()
1.3.2
Return the current faintest visible magnitude. If AutoMag has been
enabled, this method returns the faintest maginute at 45° instead.
2.1.16. celestia:setfaintestvisible(number:faintest)
1.3.2
Sets the current faintest visible magnitude. If AutoMag has been enabled, sets the faintest maginute at 45° instead.
faintest: The new faintest magnitude
2.1.17. number celestia:getminorbitsize()
1.3.2
Returns the minimum size in pixel for an orbit to be rendered.
2.1.18. celestia:setminorbitsize(number:orbitsize)
1.3.2
Set the minimum size of an orbit to be rendered.
orbitsize: The minimum size of an orbit in pixel.
2.1.19. number celestia:getstardistancelimit()
1.3.2
Returns the maximum distance of stars which are still rendered.
2.1.20. celestia:setstardistancelimit(number:distance)
1.3.2
Sets the maximum distance of stars to be rendered.
distance: The maximum distance.
2.1.22. celestia:setminfeaturesize(number:size)
1.3.2
Sets the minimum size for locations.
size: The minimum feature size for location-labels.
2.1.23. string celestia:getstarstyle()
1.3.2
Returns the current rendering style for stars, one of fuzzy, point, disc.
2.1.24. celestia:setstarstyle(string:starstyle)
1.3.2
Sets the rendering style for stars.
starstyle: The new rendering style, must be one of fuzzy, point, disc.
2.1.25. object celestia:find(string:name)
Return object by name.
name: String describing the wanted object, like "Earth" (or "Sol/Earth"), "Jupiter" etc.
2.1.27. celestia:select(object:o)
Sets the current selection.
o: The object which will be the new selection.
2.1.28. celestia:mark(object:o)
Marks object.
o: The object to be marked.
You may want to use object:mark() instead.
2.1.29. celestia:unmark(object:o)
Remove marker.
o: The object whose marker should be removed.
You may want to use object:unmark() instead.
2.1.32. celestia:settime(number:time)
Set time for this simulation in julian days.
time: Number giving the time in julian days.
See celestia:tojulianday() to convert between normal dates and julian days.
2.1.33. number celestia:gettimescale()
Get current timescale, i.e. how many seconds of simulation time equal one second of real time.
2.1.34. celestia:settimescale(number:timescale)
Set the timescale.
timescale: The new timescale.
2.1.35. number celestia:getscripttime()
Returns the real number of seconds (with fractions) since the script has been started, useful for timing purposes.
2.1.37. object celestia:getstar(number:index_number)
Return a star identified by its index number.
index_number: Number of star in star-database.
2.1.38. observer celestia:getobserver()
Return the current active observer. Note: this method returns the
observer of the active view, which can be changed by the user.
2.1.39. table celestia:getobservers()
1.3.2
Return a list of all used observers, i.e. one observer for each view.
2.1.40. number celestia:tojulianday(number:year, number:month, number:day, number:hour, number:minute, number:seconds)
Convert calendar dates to the number of julian days (see settime/gettime).
year: integer values for this date
month: integer values for this date
day: integer values for this date
hour: integer values for this date
minute: integer values for this date
seconds: float value for seconds.
2.1.41. table celestia:fromjulianday(number:jd)
1.3.2
Convert julian days to calendar dates. The returned table contains the
keys year, month, day, hour, minute, second and the respective values.
jd: the date as julian days
2.1.43. vector celestia:newvector(number:x, number:y, number:z)
Create new vector.
x: The components of the new vector. Unit is microlightyears.
y: The components of the new vector. Unit is microlightyears.
z: The components of the new vector. Unit is microlightyears.
2.1.44. position celestia:newposition(number:x, number:y, number:z)
1.3.2
Create new position object from numbers.
x: The x-component of the new vector as a number (unit is microlightyears).
y: The y-component of the new vector a number (unit is microlightyears).
z: The y-component of the new vector a number (unit is microlightyears).
2.1.45. position celestia:newposition(string:x, string:y, string:z)
1.3.2
Create new position object from URL-style Base64-encoded values.
x: The x-component of the new vector, as a string-values taken from a cel-style URL.
y: The y-component of the new vector, as a string-values taken from a cel-style URL.
z: The z-component of the new vector, as a string-values taken from a cel-style URL.
2.1.46. rotation celestia:newrotation(vector:axis, angle:w)
Create new rotation (i.e. a quaternion).
axis: Vector describing the axis of this rotation.
w: The angle of this rotation (for details check out quaternions).
2.1.47. rotation celestia:newrotation(number:w, number:x, number:y, number:z)
Create new rotation (i.e. a quaternion).
w: The values for this quaternion.
x: The values for this quaternion.
y: The values for this quaternion.
z: The values for this quaternion.
Note: passing the components of a vector as x,y,z-values is not the
same as passing the vector. If you pass a vector, a quaternion will be
created by the use of "setAxisAngle", which (I hope) is more useful in
practice. If you want to create a rotation from the values used in a
cel:-URL, use the seperate values.
Note: the (vector, w) variant of this method is deprecated to avoid
this confusion. Don't use it - use rotation:setaxisangle() instead.
2.1.48. frame celestia:newframe(string:coordsysname [, object:ref, object:target])
Create new frame of reference.
coordsysname:
String describing type of frame. Must be one of: universal, ecliptic,
equatorial, planetographic, observer, lock, chase.
ref [optional]: The reference-object for the new frame. Not needed for type "universal".
target [optional]: The target-object for this frame. Only needed for frames of type "lock".
2.1.49. celestia:requestkeyboard(boolean:enable)
1.3.2
Enable or disable callback for keyboard input.
enable: true if keyboard-input should be enabled, false to let celestia handle the keyboard.
If keyboard-input has been enabled, celestia will execute the function
with the name "celestia_keyboard_callback" for each keypress. This
function must exist when calling requestkeyboard.
The pressed key is given the function as a string-argument, containing
the UTF-8 encoding of this key (which for ASCII-chars will simply be
the string containing the normal char).
The callback-function can return a boolean indicating whether the
keypress has been handled (true) or if the normal processing should
continue (false), no return value is taken as true.
These callbacks can only happen while the script is executing wait().
2.1.50. celestia:requestsystemaccess()
1.3.2
Request permission to access the io and os libraries of Lua, which provide file-writing and program-execution. See the
Lua-docs
for details.If the ScriptSystemAccessPolicy in celestia.cfg is "ask"
(default), the user will be asked whether (s)he wants to allow this.
This question will appear with the next wait(), so you must call wait
before the request can have an effect. If you need access to os &
io, then use something like this at the beginning of your script.
celestia:requestsystemaccess()
wait(0)
If the request was successfull, the io and os libraries will simply appear and can be used.
Note: Keyboard handling is disabled after calling
requestsystemaccess(), so if you need it you must reenable it via
celestia:requestkeyboard(true). This behaviour may change in future
versions (but reenabling it won't hurt then either).
2.1.51. string celestia:getscriptpath()
1.3.2
Returns the path to this script, possibly relative to the current working dir.
2.1.52. boolean celestia:takescreenshot(string:filetype, string:name)
1.3.2
Take (if allowed) a screenshot and save it to disk, returns true if successful.
filetype: either "png" or "jpg", default is png
name: a string which will be used in the filename for this screenshot.
The limitations which were put in place for security reasons in
1.3.2
have been somewhat lifted in
1.4.0
because CEL-scripting now offers less secure screenshot taking, so this
security can be circumvented by using a CEL script anyway :-(
However screenshots still are written to the directory set by the
config option "ScriptScreenshotDirectory" in celestia.cfg, defaulting
to the main celestia directory (typically something like C:\Program
Files\Celestia\). Depending on your system, celestia may not be allowed
to write files there.
To avoid overwriting other files (i.e. non-screenshots), the filename
is always something like "screenshot-000001.png" or
"screenshot-name-000001.png", where the number is counting from 1 on
for each time you start a script, and name can be chosen by the script
- see above. The name-part is restricted to A-z, 0-9 and _ (underscore)
with a maximum length of eigth chars.
Note that taking screenshots takes some time, but any flash, print,
goto or center command in progress won't wait. This may change in
future, but OTOH nobody has complained yet.
2.1.53. celscript celestia:createcelscript(string:CELsource)
1.3.2
Create a CEL-script object from a string. If the string doesn't contain a valid CEL-script, this method will cause an error.
CELsource: a string containing the sourcecode of a valid CEL-script
A CEL-script object can be used to execute a CEL-script embedded in a
CELX-script. This is done by passing the CEL-script in a string to this
method and creating a celscript-object. Then the tick() method for the
celscript object is called repeatedly until it returns false,
indicating that the CEL-script has terminated.
Note: Lua supports a syntax for long strings using double brackets
which is useful here: [[ long string ]]. Using this you can in nearly
all cases simply copy&paste complete CEL-scripts without
modification into the CELX-script.
(back to index)observer-objects are used
to access properties specific to a view, such as the point of view, the
frame of reference, tracking, or to perform goto-commands in a view.
Note: As views (and thus observers) can be created and destroyed by the
user, observer-objects in Lua can become invalid.
Accessing an invalid observer-object will result in an error.
To ease handling of observer-objects, you can compare them with other
observer-objects using "==", which is not reliably possible with other
userdata.
2.2.1. observer:goto(object/position:target [, number:duration, number:start_inter, number:end_inter])
Go to a position, just as if pressing "g" on the keyboard.
target: an object or a position to go to.
duration [optional]: number of seconds the goto should take. Default: 5s
start_inter [optional]: ?
end_inter [optional]: ?
Note: This command returns immediately, so you probably want to wait duration seconds before continuing in your script.
Note:
Going to the position returned by object:getposition() is not the same
as going to the object, as you will go to the center of that object.
2.2.2. observer:goto(table:gotoparams)
1.3.2
Go to a position, similar to pressing "g" on the keyboard.
gotoparams: a table containing the parameters used for the goto.
Using this method, many different types of gotos can be performed.
The parameters for the goto must be given in the table (watch for
typos, unrecognized keys or values with wrong type will simply be
ignored).
gotoparams.duration: duration (number)
gotoparams.from: source position
gotoparams.to: target position
gotoparams.initialOrientation: source orientation
gotoparams.finalOrientation: target orientation
gotoparams.startInterpolation: ?
gotoparams.endInterpolation: ?
gotoparams.accelTime: ?
Note: the given positions are expected to be relative to the universal
frame-of-reference, while the non table-based goto uses positions
relative to the current frame-of-reference. Sorry for the confusion.
Note: This command returns immediately, so you probably want to wait duration seconds before continuing in your script.
2.2.3. observer:gotolonglat(object:target [, number:longitude, number:latitude, number:distance, number:duration])
1.3.2
Goto a position above longitude/latitude with given distance of object.
target: object where to go
longitude [optional]: The longitude where to go. Default: 0
latitude [optional]: The latitude where to go. Default: 0
distance [optional]: The distance from the objects center. Default: 5 times the objects radius.
duration [optional]: number of seconds the goto should take. Default: 5s
Note: longitude and latitude are in radians (0 to 2*pi), not degree (0 to 360). If necessary, use math.rad(...) to convert.
Note: This command returns immediately, so you probably want to wait duration seconds before continuing in your script.
2.2.4. observer:gotolocation(position:target [, number:duration])
Goto position target in duration seconds.
target: position to go to, in the observer's current frame of reference.
duration [optional]: number of seconds the goto should take. Default: 5s
Note: This command returns immediately, so you probably want to wait duration seconds before continuing in your script.
Note: the position is relative to the current frame of reference for this observer.
Note: the name of this method is wrong (it goes to a position, not a
location), and it expects the position relative to the current frame of
reference while most methods use the universal frame of reference.
Sorry.
2.2.5. observer:gotodistance(object:target [, number:distance, number:duration])
1.3.2
Goto given distance of target object in duration seconds.
target: object where to go to.
distance [optional]: the distance from target where to stop in km. Default: 20000
duration [optional]: number of seconds the goto should take. Default: 5s
Note: This command returns immediately, so you probably want to wait duration seconds before continuing in your script.
2.2.6. observer:gotosurface(object:target [, number:duration])
1.3.2
Goto surface of given object.
target: object on which to land.
duration [optional]: number of seconds the goto should take. Default: 5s
Note: This command returns immediately, so you probably want to wait duration seconds before continuing in your script.
2.2.7. observer:center(object:target [, number:duration])
Rotate view so that target is centered, like pressing "c" on the keyboard.
target: The object to be centered.
duration [optional]: number of seconds the centering should take. Default: 5s
Note: This command returns immediately, so you probably want to wait duration seconds before continuing in your script.
2.2.8. observer:centerorbit(object:target [, number:duration])
1.3.2
Orbit the object used as the reference in the current frame such that
the target becomes centered. This is like pressing "C" on the keyboard.
target: The object to be centered.
duration [optional]: number of seconds the centering should take. Default: 5s
Note: This command returns immediately, so you probably want to wait duration seconds before continuing in your script.
2.2.10. observer:cancelgoto()
1.3.2
Stops any goto or center command currently in progress.
2.2.11. observer:follow(object:target)
Activate follow-mode on object.
target: the object to be followed.
Follow is the same as setting the frame of reference to ecliptical with target as ref-object.
2.2.12. observer:synchronous(object:target)
Activate synchronous-mode on object.
target: the object to be synchronize with.
Sync-mode is the same as setting the frame of reference to planetographic (a.k.a. geographic) with target as ref-object.
2.2.13. observer:chase(object:target)
Activate chase-mode on object.
target: the object to chase.
Chase-mode is the same as setting the frame of reference to chase with target as ref-object.
2.2.14. observer:lock(object:target)
Activate lock-mode on the axis from the target to the currently selected object.
target: the object to chase.
Lock-mode is the same as setting the frame of reference to lock with
target as target-object and the selection as ref (or the other way
round?).
2.2.15. observer:track(object:target)
Set tracking on object, i.e. always keep object centered.
target: the object to track.
To stop tracking an object, use observer:track(nil).
2.2.16. observer:setposition(position:pos)
Set position of observer.
pos: the new position of this observer (in universal coordinates).
2.2.19. observer:setorientation(rotation:rot)
Set orientation of observer.
rot: the new orientation of this observer (in universal coordinates).
2.2.20. observer:rotate(rotation:rot)
Rotate observer.
rot: The rotation to be used on the current orientation.
2.2.21. observer:lookat(position:from, position:to, vector:up)
Set orientation of observer.
from: The point from which to look to "to". If not given, the current position is used instead.
to: The point to look at from "from".
up: A vector pointing to where "up" should be in the current view. Must not be parallel to the axis from->to.
2.2.22. number observer:gettime()
Return this observers time as julian days.
This is currently the same as celestia:gettime() (?).
2.2.23. number observer:getspeed()
1.3.2
Return the current speed of this observer. Unit is microlightyears/s.
2.2.24. observer:setspeed(number:speed)
1.3.2
Set the speed of this observer.
speed: speed of this observer in microlightyears/s
2.2.25. string observer:getsurface()
Returns string describing current surface (??) This can be "limit of knowledge" or possibly a AlternateSurface.
TODO: Check if this works as documented.
2.2.26. observer:setsurface(string:name)
Set the currently used surface.
name: The name of the surface to be used.
See getsurface()
2.2.27. table observer:getlocationflags()
1.3.2
Return a table indicating the setting of all location-flags. C.f.
celestia:setrenderflags().Possible location-flags are city,
observatory, landingsite, crater, vallis, mons, planum, chasma, patera,
mare, rupes, tessera, regio, chaos, terra, astrum, corona, dorsum,
fossa, catena, mensa, rima, undae, reticulum, planitia, linea, fluctus,
farrum, other.
Not all of these values are currently used.
2.2.28. observer:setlocationflags(table:locationflags)
1.3.2
Set the currently used locationflags. C.f. celestia:setrenderflags() and observer:getlocationflags().
locationflags:
a table holding the to be changed locationflags as keys, and
corresponding values indicating if to set or clear this flag.
2.2.30. observer:setfov(number:fov)
Set the FOV for this observer.
fov: the new FOV in radians (use math.rad(...) to convert from degrees).
2.2.32. observer:setframe(frame:f)
Set frame of reference.
f: the new frame for this observer.
2.2.33. observer:splitview(string:splitdirection [, number:splitpos])
1.3.2
Split the view for this observer.
splitdirection: "h" for a horizontal split, "v" for a vertical split
splitpos [optional]: where to split this view, default is 0.5 (in the middle).
2.2.34. observer:deleteview()
1.3.2
Delete the view of this observer (if there is at least one view
left).Note: you must no use this observer-object after this command.
2.2.35. observer:singleview()
1.3.2
Make the view of this observer the only view.
2.2.36. boolean observer:isvalid()
1.3.2
Returns true if this observer is still valid.
Note: this can change only if you are calling deleteView/singleView, or during wait() by user-interaction.