Page 1 of 1

Scripting to change models

Posted: 15.01.2011, 21:42
by fungun
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

Re: Scripting to change models

Posted: 16.01.2011, 09:03
by jogad
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())

Re: Scripting to change models

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

Tim

Re: Scripting to change models

Posted: 16.01.2011, 19:55
by jogad
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: