Multiple Environment Handling

Teardown is limited to only load one environment at a time per map. However, the game is able to handle multiple environments in one map. Because of this, you are able to insert multiple environment nodes into your map, and have the game load just one during startup via a custom title screen, and ignore the rest.

Following this step-by-step guide is one example of how to achieve this. In this guide, we will be using layers and locations.

Difficulty : Intermediate

Knowledge needed : understanding of groups, layers, locations, knowledge of LUA code and Teardown script writing, specifically Ui and registry key knowledge

 Starting off 

In this tutorial, we will use two different environment nodes - a "sunny" template environment and a "night" template environment.

Load up your map in the map editor. Create a new group in the main scene (right-click Main Scene, --> New Group).

In the " layer " category of the group options, give it two names relative to both of your environment templates (e.g. we will write the name "sunny" for a sunny day environment and "dark" for a night environment - this creates a combined layer called "sunny dark"). Create a new location inside this group, place it below your map and tag it as "hidden".

Create two more groups. Name one as "sunny" in the layer property, and the other "dark". Two layers have been created; one called "sunny" and another called "dark".

Cut/paste your "sunny" environment node inside the "sunny" group layer in the scene explorer. Cut/paste your "dark" environment node inside the "dark" group layer in the scene explorer.

We will now cut everything else inside your Main Scene excluding your three groups you just created and their contents, and paste it all inside your combined "sunny dark" group layer (will not be visible in the Layers window, use the scene explorer).



 Scripting 

Open up a text editing program. Notepad++ is recommended but a notepad file will work. If you are using Notepad++ remember to set the programming language to LUA in the language dropdown menu. Save the file as "layers.lua", in a folder called "script" inside your map folder.

Go to the scene explorer once again, and right-click Main Scene, then create a new script. Find the location of the "layers.lua" script (LEVEL/script/layers.lua). Keep this script outside of any group, just leave it in the Main Scene.

Now, assuming we're all familiar with a bit of Teardown coding, then go back to your layers.lua script file. Some required code used for this section includes:

An example of what your complete title screen code can look like:

The above code will make a title screen look like this after hitting the Play button, with the code  being a custom image: Clicking Noon will load the map using the "sunny" layer which has the "sunny" environment;

Clicking Evening will load the map using the "dark" layer which has the "dark" environment.