Rules Component

Rules Component

The Rules Component is used to define logic in your game. It is based on a trigger component so it can trigger actions. If there are no conditions applied to this component all actions are fired as soon as the component is created and added to an entity. Usally you will define a condition like a Mouse Event condition and then trigger some game action based on that. This can be used for things like buttons or collectible coins.

%STEP_TITLE%

Define if all conditions have to be met before actions are triggered or if any condition is met using the drop down between "Run If" and "Conditions". There are currently four types of conditions, Event Capture, Property Evaluation, Expression Evaluation, Keyboard Input. More condition types will be added in the future for things like mobile device multi touch events.

Click the pencil icon to open up the properties window for that action. To delete an action you have to select it in the dropdown and click the delete icon.

Event Conditions

Mouse Event

There is a Mouse Down, Mouse Up, Mouse Over, and Mouse Out event that can be captured. These mouse events are triggered relative to the exact position of the entity that this condition exists on.

Collision Event

This is used to listen for collisions that are triggered between two Collision Spatials. Both the started and stopped phase can be triggered and you can apply object type filtering by selecting the type of object to listen for. Object Types are defined in the settings window.

Level Event

This event listens for the level load or un-load event. If the level loaded condition is combined with a property evaluation condition it will wait for the property to evaluate to true and then it will trigger this event because the event capture remains true until the actions have a chance to be triggered. It will then be reset.

Property / Expression Conditions

Checking a property for a certain value or string will be needed regularly during the creation of your game so this condition can be used to evaluate numbers or strings.

Keyboard Input Conditions

This condition is used to check for user keyboard input. There is also an action to simulate keyboard input so you could have a button on screen that simulates a "Space" bar key press and have a rule setup to react to that triggered input. You can respond to the input on key down (immediately) or on key up when the user releases the key.


Code Sample

var entity : IEntity = PBE.allocateEntity();

var props : DataComponent = new DataComponent();
props.currentTime = 0;
entity.addComponent(props, "Properties");

var rule : RulesComponent = new RulesComponent();
//Add a condition to evaluate
rule.addCondition( new ConditionDataVO( ConditionType.EVENT , new MouseEventConditionData(MouseEvent.MOUSE_DOWN) ) )
//Add an action to trigger
var propertySetter : PropertySetter = new PropertySetter();
propertySetter.source = new ExpressionReference("Game.Time.virtualTime");
propertySetter.property = new PropertyReference("@Properties.currentTime");
rule.addAction( propertySetter );

entity.addComponent(rule, "Logic_MouseDown");

Follow Us For Updates