.. currentmodule:: SpaceCenter Interacting with Parts ====================== The following examples use the parts of a vessel to achieve various tasks. The :ref:`parts guide ` explains the tree of parts, attachment modes, fuel lines, staging and part modules. Deploying all Parachutes ------------------------ Sometimes things go horribly wrong. The following script does its best to save your Kerbals by deploying all the parachutes: .. tabs:: .. group-tab:: Python .. literalinclude:: /scripts/tutorials/parts/DeployParachutes.py :language: python .. group-tab:: C# .. literalinclude:: /scripts/tutorials/parts/DeployParachutes.cs :language: csharp .. group-tab:: C++ .. literalinclude:: /scripts/tutorials/parts/DeployParachutes.cpp :language: cpp .. group-tab:: C .. literalinclude:: /scripts/tutorials/parts/DeployParachutes.c :language: c .. group-tab:: Java .. literalinclude:: /scripts/tutorials/parts/DeployParachutes.java :language: java .. group-tab:: Lua .. literalinclude:: /scripts/tutorials/parts/DeployParachutes.lua :language: lua .. group-tab:: JavaScript .. literalinclude:: /scripts/tutorials/parts/DeployParachutes.js :language: javascript The script deploys the parachutes one call at a time, and the game can advance between the calls. A :ref:`server side function ` deploys them all in the same physics tick, with a single call. Python and JavaScript compile it from a function. A C# lambda holds no loop, so C# and the other clients build the loop with the :ref:`expression API `: .. tabs:: .. group-tab:: Python .. literalinclude:: /scripts/tutorials/parts/DeployParachutesFunction.py :language: python :start-after: [docs] :end-before: [/docs] .. group-tab:: C# .. literalinclude:: /scripts/tutorials/parts/DeployParachutesFunction.cs :language: csharp :start-after: [docs] :end-before: [/docs] :dedent: .. group-tab:: C++ .. literalinclude:: /scripts/tutorials/parts/DeployParachutesFunction.cpp :language: cpp :start-after: [docs] :end-before: [/docs] :dedent: .. group-tab:: C .. literalinclude:: /scripts/tutorials/parts/DeployParachutesFunction.c :language: c :start-after: [docs] :end-before: [/docs] :dedent: .. group-tab:: Java .. literalinclude:: /scripts/tutorials/parts/DeployParachutesFunction.java :language: java :start-after: [docs] :end-before: [/docs] :dedent: .. group-tab:: Lua .. literalinclude:: /scripts/tutorials/parts/DeployParachutesFunction.lua :language: lua :start-after: [docs] :end-before: [/docs] .. group-tab:: JavaScript .. literalinclude:: /scripts/tutorials/parts/DeployParachutesFunction.js :language: javascript :start-after: [docs] :end-before: [/docs] 'Control From Here' for Docking Ports ------------------------------------- The following example will find a standard sized Clamp-O-Tron docking port, and control the vessel from it: .. tabs:: .. group-tab:: Python .. literalinclude:: /scripts/tutorials/parts/ControlFromHere.py :language: python .. group-tab:: C# .. literalinclude:: /scripts/tutorials/parts/ControlFromHere.cs :language: csharp .. group-tab:: C++ .. literalinclude:: /scripts/tutorials/parts/ControlFromHere.cpp :language: cpp .. group-tab:: C .. literalinclude:: /scripts/tutorials/parts/ControlFromHere.c :language: c .. group-tab:: Java .. literalinclude:: /scripts/tutorials/parts/ControlFromHere.java :language: java .. group-tab:: Lua .. literalinclude:: /scripts/tutorials/parts/ControlFromHere.lua :language: lua .. group-tab:: JavaScript .. literalinclude:: /scripts/tutorials/parts/ControlFromHere.js :language: javascript Combined Specific Impulse ------------------------- The following script calculates the combined specific impulse of all currently active and fueled engines on a rocket. See here for a description of the maths: https://wiki.kerbalspaceprogram.com/wiki/Specific_impulse#Multiple_engines .. tabs:: .. group-tab:: Python .. literalinclude:: /scripts/tutorials/parts/CombinedIsp.py :language: python .. group-tab:: C# .. literalinclude:: /scripts/tutorials/parts/CombinedIsp.cs :language: csharp .. group-tab:: C++ .. literalinclude:: /scripts/tutorials/parts/CombinedIsp.cpp :language: cpp .. group-tab:: C .. literalinclude:: /scripts/tutorials/parts/CombinedIsp.c :language: c .. group-tab:: Java .. literalinclude:: /scripts/tutorials/parts/CombinedIsp.java :language: java .. group-tab:: Lua .. literalinclude:: /scripts/tutorials/parts/CombinedIsp.lua :language: lua .. group-tab:: JavaScript .. literalinclude:: /scripts/tutorials/parts/CombinedIsp.js :language: javascript The script reads the thrust and specific impulse of each engine with separate calls, which can land in different physics ticks. A :ref:`server side function ` reads them all in the same tick, with a single call. Python, C# and JavaScript compile it from a function, and the other clients build it with the :ref:`expression API `: .. tabs:: .. group-tab:: Python .. literalinclude:: /scripts/tutorials/parts/CombinedIspFunction.py :language: python :start-after: [docs] :end-before: [/docs] .. group-tab:: C# .. literalinclude:: /scripts/tutorials/parts/CombinedIspFunction.cs :language: csharp :start-after: [docs] :end-before: [/docs] :dedent: .. group-tab:: C++ .. literalinclude:: /scripts/tutorials/parts/CombinedIspFunction.cpp :language: cpp :start-after: [docs] :end-before: [/docs] :dedent: .. group-tab:: C .. literalinclude:: /scripts/tutorials/parts/CombinedIspFunction.c :language: c :start-after: [helpers] :end-before: [/helpers] .. literalinclude:: /scripts/tutorials/parts/CombinedIspFunction.c :language: c :start-after: [docs] :end-before: [/docs] :dedent: .. group-tab:: Java .. literalinclude:: /scripts/tutorials/parts/CombinedIspFunction.java :language: java :start-after: [docs] :end-before: [/docs] :dedent: .. group-tab:: Lua .. literalinclude:: /scripts/tutorials/parts/CombinedIspFunction.lua :language: lua :start-after: [docs] :end-before: [/docs] .. group-tab:: JavaScript .. literalinclude:: /scripts/tutorials/parts/CombinedIspFunction.js :language: javascript :start-after: [docs] :end-before: [/docs] .. seealso:: The combined specific impulse of each stage is also available directly from the staging API, as :attr:`Stage.specific_impulse` on the object returned by :meth:`Vessel.stage_at`.