Jump to content
  • Setting up ScenarioModules - A short guide about how that's done.


    HarvesteR
     Share

    It ocurred to me that there is little to no documentation at this point about the new ScenarioModules and how to add them to your game. With that in mind, I've written this brief guide as to how they are used. I'm assuming you already have some experience writing PartModules, in which case it should be relatively straightforward to learn how ScenarioModules operate. If not, I strongly suggest reading through the available PartModule coding tutorials and (admittedly very incomplete) documentation first.

    Let's get started then:

    Scenario Modules, just like PartModules, are compiled into dlls that go in the Plugins folder. In fact, nothing stops you from having ScenarioModules sharing dlls with PartModules. The dlls in Plugins simply add their classes to the game assembly.

    Once added, a ScenarioModule is loaded into the game through SFS files. In very much the same way you set up a PartModule in a part.cfg, you set up a ScenarioModule in an .sfs file:


    GAME
    {
    version = 0.17.0
    Title = Orbiting 101
    Description = This training scenario covers the basics of flying a blablabla....
    // mode 0: Sandbox - mode 1: Career (not available yet), mode 2: Scenario, mode 3: Non-Resumable Scenario
    Mode = 3
    // scene to load when starting this save.
    scene = 7
    PARAMETERS
    {
    // flight parameter stuff
    }
    FLIGHTSTATE
    {
    // flight state data (in 0.16 this was your entire sfs file)
    }
    SCENARIO
    {
    // the name of the ScenarioModule class to spawn
    name = TutorialOrbit101
    // the scene in which the module gets spawned (7 = flight)
    scene = 7
    }
    }



    The only limitation at the moment is that to add a scenario module to your ongoing sandbox game, you'll need to manually add the module config to your persistent.sfs. Once added, it gets loaded into the persistence data structure and will remain in your sfs file even as it gets resaved and rewritten.

    ScenarioModules have one main difference from PartModules though. Because they are made to run on any scene, you must specify a target scene in which your module will run. Currently, modules can only run on one scene at a time. When a scene starts, the scenario module runner attaches all ScenarioModules that target that scene as a MonoBehaviour on an empty game object in the scene. You can use all MonoBehaviour events (except Awake), and code it in very much the same way you code part modules... Of course, there is no reference to vessel or part, since the module isn't attached to one.


    Hope this helps.

    Cheers

     Share


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...