E Language Reference

event, raise

See Also - Example

The event keyword declares a special type of function that will be called when that event name is raised using the raise keyword . Event functions can also be defined for any type of class and can include a conditional execution statement which may result in the event function not being called.
The raise keyword calls any events using the same name and parameter declaration as that which was specified in the call to the event.


event alias [for class-name] ([parameters]) [priority (priority-index)[: on (condition)]
{
      -- function body
}
raise [class-instance.]alias ([parameters])

Remarks

An event type function is very similar to a normal function but returns no value. The on condition is evaluated as if it were placed at the start of the function body, returning if the condition evaluated to false before the function body is executed . The for tag specifies the class type this event will be defined for. If the event is specified to be an object event, the this keyword can be used throughout the function body and the on condition to access the instance this event was called on. This way events can be dynamically added to a class without it needing to declare any information about it.

An event function is syntactically similar to [class-name:] alias ([parameters]) null { [if (!condition) {return }] -* function body *- }.

Example

-- events.e
-- example of event functions

-- this implementation is always called and has a higher priority than the second implementation
event onEnterFrame (real deltatime) priority (0)
{
      console:print ("This is a frame")
}

-- this implementation will be called on every odd frame (i.e. frameNum % 2)
event onEnterFrame (real deltatime) : on (game:instance().frameNum % 2)
{
      console:print ("This is an odd frame")
}

-- this implementation will only be called on an object instance of this type
event onEnterFrame for game:actor (real deltatime)
{
      -- this points to the object instance the event was raised for
      console:print ("This is an actor named " + this.getName ())
}

main (null) int
{
      game:instance ().frameNum = 0
      raise onEnterFrame (1.0) -- triggers the first global implementation

      game:instance ().frameNum = 1
      raise onEnterFrame (1.0) -- triggers both global implementations because the on conditional evaluates to true

      game:actor ^ a = game:instance ().getActor ("Player 1 ")
      raise a.onEnterFrame (1.0) -- triggers the third class implementation on this object
      -- note that an object does not need to know about any events created for it
}

-- Output
This is a frame
This is a frame
This is an odd frame
This is an actor named Player 1

See Also


To make a suggestion or report a bug about Help or another feature of this product, go to the sourceforge project.