Jump to content

Celestia/Celx Scripting/CELX Lua Methods/Celx celscript

From Wikibooks, open books for an open world

Celx Scripting: CELscript

[edit | edit source]

CELscript

[edit | edit source]

Within CELX scripting it is possible to create a "celscript" object from a string, containing a valid CEL script.

A "celscript" 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 the celestia:createcelscript() method and thus create a "celscript" object. If the string doesn't contain a valid CEL script, this method will cause an error.

Methods

[edit | edit source]

This chapter contains a list of all available celscript methods, which can be used on "celscript" objects.

boolean celscript:tick()

Return a boolean, indicating that the CEL script within the "celscript" object has terminated.

  • true, CEL script is still running.
  • false, CEL script has terminated.

Notes:

  1. LUA supports a syntax for long strings using double brackets which is useful here. Using this you can in nearly all cases simply copy and paste complete CEL scripts without modification into the CELX script.
  2. When using CEL script parts within a CELX script, the PAUSE function by pressing the [Spacebar] key will not work completely correct. Although the scene you’re looking at will pause directly, the CEL script parts will continue to run in the background, resulting in a part of the script being visually skipped when you press the [Spacebar] key again to continue the script.
  3. When using a "celscript" object repeatedly within a CELX script, it is advised to first define the following function at the beginning of your script, which can be used on different places in the main script:
function CEL(source) 
   local script = celestia:createcelscript(source) 
   while script:tick() do 
      wait(0) 
   end 
end

<... other CELX script code ...>
CEL([[{ string:cel }]])
<... other CELX script code ...>

Example:
The following example orbits Saturn for 12 seconds, using CEL commands within a CELX script:

function CEL(source) 
   local script = celestia:createcelscript(source) 
   while script:tick() do 
      wait(0) 
   end 
end
--
CEL([[{
   select { object "Sol/Saturn" }
   center { }
   goto   { time 3 distance 8 up [ 0 1 0 ] upframe "equatorial" }
   wait   { duration 3 }
   orbit  { axis [ 0 1 0 ] rate 30 duration 12 }
   }]])


Return to the celscript method index.