Properties

Your plugin properties specify what appears in the properties bar when your plugin is selected. Construct 2 adds its own properties for most plugins. However, you can specify custom properties which are shown at the bottom of the properties bar. For behaviors, properties appear in a sub-category of the behaviors category.

Properties are specified in edittime.js. By convention, they follow the ACE definitions.

    var property_list = [
    	// a list of cr.Property objects
    	];

Each property should be a new cr.Property object:

new cr.Property(type, name, initial_value, description[, param, readonly])

type
One of the following property types:

ept_integer
An integer number. Floating point numbers cannot be entered to integer properties.

ept_float
A floating point number.

ept_text
A text property.

ept_color
A color selector. The runtime receives an rgb string, e.g. "rgb(255,255,255)".

ept_font
A font selector. The runtime receives a string formatted "facename,size,weight,italic".

ept_combo
A combo box property. Items are specified in the param parameter of cr.Property as a pipe-separated string, e.g. "One|Two|Three".

ept_link
A link property. Links do not have any associated value nor are they passed to the runtime; they simply allow you to do something in OnPropertyChanged() when it is clicked.

ept_section
Creates a new header in the properties bar. Useful for splitting up long property lists in to groups, like with the Particles object.

name
The name of the property.

initial_value
The initial value of the property. This must be a javascript number for integer and float properties; a javascript string for text properties; an RGB value for color properties (e.g. cr.RGB(255, 255, 255)); a string in the format "Facename,size" for font properties; the string of the default item to select for combo properties; and the link text for link properties.

description
The text that appears as a tip at the bottom of the properties bar. Try to keep it brief, but as helpful as possible to the user. Any opportunity to save the user a trip to the manual is worth taking.

param (optional)
For combo properties, a pipe-separated string specifying the combo box items, e.g. "One|Two|Three". For link parameters, this can be one of the following values:

"firstonly"
By default, clicking a link calls OnPropertyChanged() once for each of the selected instances. If you are performing an action on the object type, such as invoking the image editor, specifying "firstonly" calls OnPropertyChanged() once only for the first selected instance rather than repeatedly.

"worldundo"
Create a 'world' undo point before calling OnPropertyChanged(). This allows undoing any change in position, size or angle. Sprite uses this so 'Make 1:1' can be undone.

readonly (optional)
Set to true to make the property read-only (uneditable).

Getting property values at runtime

In your instance's onCreate() function in runtime.js, properties are available via the array this.properties[]. This is an array of the property values. The values are in the same order as the properties were added, excluding link properties. For example, if you have two link properties followed by three integer properties, this.properties only has three elements (the three integer properties in the order they were added).

Tags: