E Language Reference

Functions Definitions

See Also - Example

Function declarations provide the basis for defining and calling a global or object member function

[access-modifiers] alias ([parameters]) return-type
      -- function body


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.


-- functions.e
-- example of event functions

-- this implementation is always called
event onEnterFrame (real deltatime)
      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 ("player0")
      raise a.onEnterFrame (1.0) -- triggers the third for 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 player0

See Also

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