Inspector and Connectors

inspectorWhen a single entity is selected, its Game Object properties such as ID, position and facing, and a varying number of components and their properties are displayed in the inspector window. Let’s take a look at the inspector by adding a turtle entity to the level.

You can change the turtle’s behavior under the monster component with the “AI State” drop down box: the default state is that the monster will wander around in the dungeon by itself and the guard state will make the monster stand in place until it sees or otherwise senses the player. You can also add items for the monster that will be dropped when it is killed. Pressing on the “+” adds a new item and you can start typing the name of an asset (say, a dagger for instance) in the text field and the text will autocomplete itself as you type to make it quicker to locate and add items to it.

When looking at the parameters of the monster component you might have noticed the connectors. Connectors are a simple but powerful way of creating all sorts of contraptions, puzzles, traps and logic into the levels. To try it out, add a dungeon_pressure_plate and a dungeon_door_portcullis into the dungeon and select the pressure plate and click on the “+” button. Connectors are simply a way of creating gameplay logic by defining that when an event happens to the pressure plate, a target entity performs an action. In this case for example, we can make the portcullis to open when a weight is placed on the pressure plate and to close when the weight is taken off. To start off, let’s first define the portcullis as the target of the connector by pressing the “?” button by the “Target” text field and then clicking on the portcullis on the Map View. This will add the ID of the portcullis into the target text field and, to illustrate the connection, an arrow is drawn between the entities on the map view.

Now, the pressure plate is already functional and you can try it out in the preview but it’s not doing exactly what we want it to do quite yet: now when you step on it the door opens as it should but when you step off the plate the door still stays open. If we take a closer look, we can spot two problems: 1) we only have an action that opens the door and 2) we only perform an action when the pressure plate is activated. Different triggers have different amounts of events. Pressure plates have onActivate, onDeactivate and onToggle. The activate event happens when a weight is put on a pressure plate or an alcove, a lever is pulled down and deactivate happens when the opposite is done. In this case we need the door to open when the plate is activated and the door to close when the plate is deactivated. You could simply add a second connector to the pressure plate that closes the door when the plate is deactivated but an alternate, and perhaps a little more elegant solution, would be if we just use a single connector with the event type of onToggle (so that the action is taken on both activate and deactivate) and then send a “toggle” (which will open the door if is closed and vice versa) action to the portcullis.
Floor Triggers, Secrets and Spawners
If you ever need to trigger events without the player noticing that he has just stepped on a pressure plate, a good way to do it is to use floor_trigger asset: it has the same functionality as the normal pressure plate has but you just simply can’t see it. Just keep in mind that if you don’t want monsters or thrown items to accidentally trigger the event, be sure to disable those parameters from the inspector. Good example cases where you often want to use floor triggers are when you need to activate a secret or a spawner entity. Secrets are a special asset whose purpose are indicating it for the player when he has discovered a secret area and then tallying up the total number of secrets discovered in his game statistics. Spawners are a little more interesting since not only can you spawn monsters from it but you can use it to launch spells as well to create traps or puzzles. The cooldown parameter in a spawner defines in seconds how much time is needed before the spawner can spawn again if it is activated again. This can be useful in controlling the size of monster populations or to limit the total amount of fireballs flying through the air: a great number of spells can be very taxing on the game’s performance. A cooldown value of 0 means that the spawning speed is unlimited.

If you want to create “Spectral Relay” -style puzzles, you can spawn a blob spell (it’s a spell that the player cannot cast and its sole purpose is to be used in puzzles) and then catch the spell with a receptor, whose entityType is set to blob, and trigger something by adding a connector to it.

Using Counters and Timers
Counting things like button presses or triggering an event when a certain amount of keys are inserted into locks is a common occurrence in Legend of Grimrock levels. For most of these cases, using counter assets are the most simple solution. Counters are very straightforward: they just contain a single number that you can increment and decrement with connectors from other entities and you can also add connectors to the counter itself which will be triggered when the counter’s value reaches zero. So if you would want to create a button you need to press three times, you would need a counter whose initial value is 3 and then just make sure that a connector in the button has the counter entity as its target and decrement as its action. This means that any time you would press the button, the counter’s value goes down by 1 and after three presses the counter would reach 0 and any connectors added to the counter entity would be activated.

Doors that open with a delay or carefully timed sequences of events can be created by using timer assets. Timers are quite simple: if a timer is active, it waits for the duration of its timer interval -parameter (in seconds) and then activates its connectors. Once a timer is activated, it will not stop until something deactivates it so by default its connectors will be activated perpetually, once per timer interval. If you wish to stop the timer after a single completed cycle, just tick the disableSelf-checkbox. By default timers will start on the game init so if you want a timer that is activated by a separate event, you need to disable the timer component by clearing the checkbox next to the timer component.

More intricate sequences can be created by using counters along with timers. You can set a counter as the target of a timer’s connector, so it decrements a counter every time a timer ticks and then the counter triggers once reaching 0. You can even use multiple counters with different values to create even more intricate scenarios but when working on complex sequences, scripting can very easily be the easier, more elegant solution. But before we get into scripting let’s take a look at the level parameters and how to export and share your dungeons.