Scripting to change models

All about writing scripts for Celestia in Lua and the .cel system
Topic author
fungun
Posts: 315
Joined: 30.07.2007
Age: 63
With us: 17 years 6 months
Location: Iowa, USA

Scripting to change models

Post #1by fungun » 15.01.2011, 21:42

I have my new Drydock addon finished, except I would like to know is there a way to change between 2 models so an observer can see the difference.
Example pics-

Thanks,
Tim

Avatar
jogad
Posts: 458
Joined: 17.09.2008
With us: 16 years 4 months
Location: Paris France

Re: Scripting to change models

Post #2by jogad » 16.01.2011, 09:03

Hi,

I suggest having the two versions of your spacecraft in your stc file.
First and default version with the declaration
Visible true
and the second version with the declaration
Visible false

This way only one is visible at the same time.

Now a simple script can switch the visibility of the two objects.
This relies on the object methods visible() and setvisible() available for celestia version 1.6 and later.
for example:

Code: Select all

spacecraft1=celestia:find("Sol/Earth/Spacedock/USS Enterprise")
spacecraft2=celestia:find("Sol/Earth/Spacedock/USS Enterprise2")
spacecraft1:setvisible(not spacecraft1:visible())
spacecraft2:setvisible(not spacecraft2:visible())

Topic author
fungun
Posts: 315
Joined: 30.07.2007
Age: 63
With us: 17 years 6 months
Location: Iowa, USA

Re: Scripting to change models

Post #3by fungun » 16.01.2011, 18:25

Thanks, jogad. It works perfect. :D
Now if I could just figure out how to assign a keystroke to run it. :wink:

Tim

Avatar
jogad
Posts: 458
Joined: 17.09.2008
With us: 16 years 4 months
Location: Paris France

Re: Scripting to change models

Post #4by jogad » 16.01.2011, 19:55

fungun wrote:Now if I could just figure out how to assign a keystroke to run it. :wink: Tim

This time, it is less easy.
Have a look at the celestia:registereventhandler() method.

You will find an example here:
http://en.wikibooks.org/wiki/Celestia/C ... enthandler
:mrgreen:


Return to “Scripting”