Creating Custom Types

Defining your own types can be useful in complex projects. Types consist of properties, functions, and subroutines, bundled together in an easy-to-understand object.

Learn more about "Type Conversion" on page 1 in general, to determine if a regular type or a custom type is best for your needs. If a custom type is required, chose which is best: a custom type in the context of a configurator or scene, or a custom type in the global context of your entire implementation.

Here, we describe custom types in the context of a configurator or scene.

 

Once a type has been created, you can refer to it when creating new variables of that type. This is called "instantiating" a type as a variable. The new variable can be used to more easily manage your data.

 

Properties

Properties of types are similar to regular variables, except they are assigned to that type. You can set properties on an instance of that type.

Functions and Subroutines

Like regular functions and subroutines, a type can have its own built-in functions and subroutines, which are called within the context of the instance of that type. Within the function or subroutine you have access to that instance's property values.

Examples of Custom Types

This type provides a way to describe the properties of a wheel, which consists of a radius and width. A helper function can use the radius data to provide the circumference using the well-known formula 2 * PI * r. One can then instantiate the wheel:

You can also use the slot in the declare property block within the type to define default property values. The following code would result in the same value for circumference.

The "This" Variable

This is a special variable in the scope of a type function or subroutine which gives you access to that type's properties, functions, and subroutines. For example, in the screenshot above you can see how a function inside the type performs a calculation based on a property of that type.

Was this article helpful?