CEL in CELX scripts

All about writing scripts for Celestia in Lua and the .cel system
Topic author
Harry
Posts: 559
Joined: 05.09.2003
With us: 21 years 2 months
Location: Germany

CEL in CELX scripts

Post #1by Harry » 13.03.2004, 12:40

Hi,

as already mentioned CELX-scripts can now include the source of CEL-scripts. This feature is available as of v1.3.2pre6.

I think the easiest way to use it is this:

- include this function at the top of your CELX-script:
UPDATE: Corrected stupid error (didn't check if the CEL-script had ended)

Code: Select all

function CEL(source)
  local script = celestia:createcelscript(source)
  while script:tick() do
    wait(0)
  end
end


- below this enclose any CEL-scripts like this:

Code: Select all

CEL([[
{
  ...
}
]])

That's it. Note: the [[...]] is just a special way to define a string in Lua, instead of using "...". This way you don't have to escape any "" within the CEL-script, but better make sure there is no "]]" within the CEL-script.

You can execute an arbitrary number of CEL-scripts like this, one after the other, and add some Lua-commands between them.
Or maybe split a CEL-script in multiple smaller scripts, which then can be executed conditionally (for example after receiving a keypress).

Harald
Last edited by Harry on 14.03.2004, 09:12, edited 1 time in total.

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

Post #2by don » 13.03.2004, 20:21

Hi Harald,

This is great news, thank you!

Your description is a bit confusing to me. Could you provide a simple celx script with a couple of 3 or 4 line CEL scripts defined within it as an example?

Thanks a bunch!
-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
Harry
Posts: 559
Joined: 05.09.2003
With us: 21 years 2 months
Location: Germany

Post #3by Harry » 14.03.2004, 09:09

Ups, I just saw I had a stupid error in my code above, so the script never ends (copy&pasted the wrong file) - Sorry.

This is the conversion of start.cel (without the comments):

Code: Select all

function CEL(source)
  local script = celestia:createcelscript(source)
  while script:tick() do
    wait(0)
  end
end

CEL([[
{
   select { object "Sol/Jupiter/Io" }
   follow {}
   goto { time 5 }
}
]])


Of course this wouldn't make much sense, because it's simpler to not use Lua at all. But you could do something like:

Code: Select all

function CEL(source)
  local script = celestia:createcelscript(source)
  while script:tick() do
    wait(0)
  end
end

CEL([[
{
   select { object "Sol/Jupiter/Io" }
   follow {}
   goto { time 5 }
        wait { duration 5 }
}
]])

-- do stuff in Lua here, e.g. show explanation
-- and wait for keypress to continue

CEL([[
{
   select { object "Sol/Earth/Moon" }
   follow {}
   goto { time 5 }
}
]])

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

Post #4by don » 15.03.2004, 16:13

Thank you very much Harald! :D
-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”