Time for action - placing your entity into your level

After we have created both files, we should now be able to place our new entity within Sandbox:

  1. Open Sandbox and create a new level (or load your level of choice).
  2. In the RollupBar tab, select the first tab and choose Entity in the Objects list. If you scroll in the Browser window to Others and open this subfolder, you should find your new Teleporter entity.
    Time for action - placing your entity into your level
  3. You can drag-and-drop the Teleporter into your level, as seen in the following screenshot. Once you do this, you can select the entity and just modify the properties in the RollupBar tab.

    Note

    You can add your entity multiple times and change the properties individually for each Teleporter that is placed in your level. The entity that we defined is some sort of template class (a definition about an entity). You can simply drag-and-drop the Teleporter entity from the RollupBar tab into the level of this entity for which we are creating instances.

    Time for action - placing your entity into your level
  4. If you select your Teleporter, you will find the properties, which you just defined in the Lua script, in the RollupBar tab under Entity Properties.

Note

The property object_3DModel is just displayed as 3DModel, and if you click on it you can open a browser to select a 3D model. This is because we named the property object_<some name>. There are a few prefixes that you can use in front of your property name to allow Sandbox to show the correct selection box. Let's see a few prefixes:

  • object_<name> for the model selection dialog.
  • b<name> for a checkbox.
  • The initial value of a property will also define the type, such as number, string and so on.

What just happened?

With the .ent file in place that points to a Lua script, we can easily extend our entity library with our own entities. The basic functions we need are the constructor, OnInit, OnPropertyChange, and OnReset. Within the Properties table, we can define properties. Those properties can be adjusted separately for each entity of this type that is present in our level.

How to interact with entities via Lua script

Since the entity we just created is a bit boring, we now need to define some interactions with it. This can be done simply by modifying the Lua script we just wrote.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.204.208