Boot Files¶

There is a kicking system you lot can use in kOS to have a kOS reckoner automatically load a kerboscript file and run it when the computer boots upwards.

Brusk version and example¶

Here's the tl;dr version of how to use a boot file:

  1. Identify a kerboscript program file in the archive "0:/boot/" directory. For example, "0:/boot/myboot.ks" . Make sure the file ends in .ks .
  2. Bring upwardly the vessel into the VAB or SPH. Rightclick the kOS calculator role, and use the slider widget to select your file from step one higher up.
  3. When yous save and launch this vessel, it should re-create that file to the local drive and run it once the ship is loaded onto the launchpad.

Example:

                                // Identify this file in your annal and telephone call it "kick/myboot.ks".                expect                until                ship                :                unpacked                .                clearscreen                .                print                "Hi. I am the boot file."                .                print                "If yous see this, that proves the boot file ran."                .              

Then do steps 2 and 3 above. Launch the vessel and you should see the message in the kick script was run if you open the last.

There'due south a lot more you should learn about how the booting system works before you use it - but that's the brusk version.

Read on to learn more.

Telling kOS which file is the kicking file¶

There are two ways to tell the kOS modernistic which file is the one yous wish to take exist your boot file - ane is through the VAB or SPH editor edifice when creating the vessel, and the other is through kerboscript code itself once the vessel is loaded and on screen.

In the VAB or SPH¶

Figure of selecting a boot file

You may select a boot file from the Vehicle Assembly Building or Spaceplane Hangar. To exercise this you lot must accept placed the file(southward) you lot wish to exist bachelor for booting into the kick/ directory of your archive binder. For a reminder, this ways it is located here on your computer:

[Kerbal Space Program's Folder]/Ships/Script/boot/

where "[Kerbal Space Program's Folder]" is wherever your kerbal space programme game is installed.

Files placed here MUST end in ``.ks``. The files volition not be seen in the VAB or SPH if they don't accept a .ks ending.

When you accept files bachelor there in the archive boot folder, then they will appear in the VAB or SPH when you correct-click on a part that contains a kOS reckoner, as shown in the figure here.

Be Aware that just the files that were present when you kickoff entered the VAB/SPH will be in the list. If you add together a new file to the ``kicking/`` folder, you must leave and re-enter the VAB/SPH to make that file appear in the listing.

Please pay attention to the topic beneath, "Booting When Spawning to launchpad", to see exactly when and how the files become copied to the computer when you use this method of selecting the kick file (from the VAB or SPH).

From Script Lawmaking¶

Kerboscript code can also alter the boot file on the fly with this command:

                                    set up                  core                  :                  bootfilename                  to                  "any_filename_here"                  .                

When you exercise this, then "any_filename_here" becomes the new boot file for that kOS computer, and information technology volition be what gets booted on that kOS computer in the future, instead of whatever may have been selected for information technology in the VAB/SPH.

When using this method of selecting the kick file, unlike when using the VAB/SPH method, the file volition not automatically get copied from the archive to your local drive on the kOS estimator. It must exist a file that already exists on the kOS computer'south local drive when the booting occurs. Y'all can use a file from any folder of the local volume you like (it does non have to take kick/ in the pathname), merely it must be from the local volume and not from the archive. In fact if you use a drive indicator such every bit "0:" or "1:" in the filename, it won't work.

When practice kicking files run¶

If a kick file is set, then the boot file gets run under any of the following conditions:

  1. Whenever the kOS computer is turned on later on having been turned off.
  2. When electric charge is depleted simply gets restored later on. (This is but a special instance of case (i) above, since losing ability turns the figurer off and regaining power turns it back on.)
  3. When you leave the scene, and then return to the scene later on. The kOS reckoner reboots when yous reload the scene.
  4. When you first launch the vessel to the launchpad or rail. Meet below to run into the exact sequence of events that gets the file copied to the ship when you do this.
  5. When the REBOOT. control is run by a script or at the terminal.

Because boot files are run whenever the scene is reloaded, they can be a useful manner to make your probe do things fifty-fifty when they have no antenna contact from habitation.

Warning about ship:unpacked¶

Because the boot file begins the instant the scene loads, there tin exist a problem. Kerbal Space Program loads the scene immediately, starts up the kOS modules, and then a 2d or 2 later it "unpacks" the vessel. Without going into besides much detail about what "unpacks" means hither, the short version is that for the few seconds the vessel is loaded but non yet unpacked, half the stuff on the vessel doesn't work however. You attempt to move the throttle and nothing happens. Yous try to printing spacebar to stage and nada happens. You try to steer with WASD keys and nothing happens. This as well affects kOS'south own attempts to control the ship. If y'all run a kick script and permit's say the very first affair the boot script tries to do is throttle upward and turn on the engine, it might non actually piece of work considering Kerbal Infinite Plan still has the ship in its "packed" land when you tried to do that. The control executes without complaint, only has no effect.

To avoid this problem, you can put this line at the tiptop of your kick file:

                                    // put at the superlative of nigh kick files:                  print                  "Waiting for ship to unpack."                  .                  look                  until                  ship                  :                  unpacked                  .                  impress                  "Ship is at present unpacked."                  .                  //                  // .. The remainder of your boot file goes here ..                  //                

So why doesn't kOS itself but wait until the ship is unpacked earlier information technology starts booting the computer? The reason this is not washed is considering of the following three things taken in combination:

  1. If the vessel is not the electric current agile vessel, only it IS inside 2.five km of the active vessel, then it will be loaded but still packed, and stay packed until you get close to information technology with the agile vessel. Waiting until ship:unpacked would hateful the kick script on that vessel will never run at all until you bring the active vessel shut plenty to it to unpack it.
  2. There are nonetheless valid things a kOS script can accomplish while the vessel is in a packed state. Information technology just tin can't make the ship move.
  3. The send also becomes packed when nether time warp. You lot might withal want a script to be running while in time warp, especially if what it's doing is waiting for the right conditions where it will choose to finish the time warp.

More information on what "packed" and "loaded" actually hateful can be found here, merely exist warned, it tin exist a circuitous topic.

Booting when spawning to launchpad¶

When you lot outset spawn a new vessel on the launchapd from the VAB (or when you spawn it to the runway from the SPH), kOS performs the following initial steps to get the boot file copied from annal to the transport:

  1. Creates a folder called boot/ on the kOS calculator's local volume ( 1:/ ).
  2. Copies the boot file from the archive's boot/ folder to the local volume's kicking binder.
  3. Important: NOW is the bespeak where Kerbal Space Program saves the game for the purpose of beingness able to "revert to launch".
  4. kOS begins running that local copy of the boot file.

Please brand notation of when during those steps Kerbal Space Program saved the game for the sake of doing a revert to launch. If you edit the boot file on the archive, and so revert to launch, then your vessel will not have the newly edited boot file copied to it because it doesn't go all the mode back to exercise step ane and 2 from the in a higher place list again. To force it to utilise the new version of the boot file you will either have to revert it all the way to the assembly building and re-launch it from at that place, or terminate the boot file with ctrl-C and manually copy the new file and reboot.