Page 1 of 1

CEL in CELX scripts

Posted: 13.03.2004, 12:40
by Harry
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

Posted: 13.03.2004, 20:21
by don
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!

Posted: 14.03.2004, 09:09
by Harry
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 }
}
]])

Posted: 15.03.2004, 16:13
by don
Thank you very much Harald! :D