About Sending and Receiving Signals with Objects

You can use the sends signal (driver) and has received signal (sensor) capacities in the Capacity Selector to emit or receive a signal (string message) with the actors of your scenarios.

These capacities let you produce user-defined signals with the actors in your scenarios. They let you emulate your own custom events more conveniently.

This page discusses:

See Also
About Scenarios
About Natural Language
About the Behavior Editor
Storytelling
Working with Paragraphs
Using Sentences

Introduction

The sends signal and has received signal capacities follow the logic of the observer design pattern commonly used in software development.

The observer design pattern is a behavioral pattern where a first object (subject) emits a signal, message, or notification to other dependent objects (observers). These observers subsequently perform an action when they receive the notification. The subject and its condition maintain this list of dependent observers.

The observer design pattern helps to reduce the dependencies between the subject and the observers, with the following benefits:

  • The subject requires notifying the observers only. Therefore, the subject does not need to know the specific conditions of the observers.
  • You can add and remove observers or modify their conditions without affecting the initial subject.
  • You reduce the hypothetical costs of having to modify chunks of your code while solidifying its adaptability.

Sending and receiving signals greatly simplifies the construction of your scripts by:

  • Uncluttering your scenarios.
  • Reducing the number of drivers and sensors in your sentences.
  • Alleviating the dependencies between the objects.
  • Improving structural clarity.
  • Dissociating inputs from outputs more prominently.

Note: The StuSignalEvent event lets you interact with the signals emitted in Natural Language to use them in JavaScript and the Behavior Editor. The event also lets you send signals from JavaScript that Natural Language can receive.

For more information, see the JavaScript API Guide of Creative Experience.

Modalities

The sends signal and has received signal capacities both take a string parameter (no custom Event type) that defines the signal (as a message) to send or receive.

The signal is case-sensitive. For example, "myMessage" does not equate "mymessage".

Important: There is no automatic management for the lifecycle of the signal.

The Scenario Editor does not perform any verification on the validity of your signal. There are no warnings or errors that indicate if you send the signal properly, if its spelling is correct, etc.

The capacities require the following actor types:

  • 3D actors
  • 2D UI actors
  • Logical actors

You cannot send or receive signals without an actor. There is no general broadcasting system.

In addition, you cannot send messages to inactive actors. Ensure that your actors are active, especially when transitioning between scenes.

Practical Application

Consider the following paragraph in a scenario:

  • If myActor1 is visible Do myActor2 starts
  • If myActor1 is visible Do myActor3 rotates
  • If myActor1 is visible Do myActor4 hides

Changing the subject (myActor1) requires changing all the other sentences for the whole paragraph to stay valid.

Using the observer design pattern and a signal system, you can make this paragraph more adaptable and convenient to modifications:

  • If myActor1 is visible Do myActor1 sends signal mySignal
  • If myActor2 has received signal mySignal Do myActor2 starts
  • If myActor3 has received signal mySignal Do myActor3 rotates
  • If myActor4 has received signal mySignal Do myActor4 hides

Using this construction, changing the subject (myActor1) requires changing only the first sentence for the whole paragraph to stay valid.

Compatibility of the Capacities with Logical Operators

You can use the sends signal driver with all the sensor operators. When using the While operator with sends signal, the Scenario Editor displays a warning indicating that you can encounter performance issues.

You can use the has received signal sensor with the If and Each Time sensor operators but not with While because it is an event.

Sending a signal corresponds to sending an event and occurs once per frame. Therefore, using Each Time sends a signal every time the condition meets its requirements.

In addition, you cannot negate the has received signal sensor because negating an event is not relevant.

The following table summarizes the compatibility of each capacity with the logical operators:

N/A If Each Time While
send signal

(potential performance issues)
has received signal