• entries
    437
  • comments
    1000
  • views
    335833

4E4 Event system

Sign in to follow this  

58 views

The skeleton event system is now up and running. It's a prretty nice system and I'm pleased with how it works. The game is, in theory, 100% scriptable and as such, all events (bar a few internal exceptions) will call a scripted method. As each entity has a unique name, you can effectively override any event for any entity by name.

For example:-

I have two entities of the 'Alien' entity class with ids "Alien0001" and "myAlien". I have bound the KEY_UP key to the 'MoveUp' event which is tied to the player's character, 'myAlien'.

What happens now is that the game will detect the keypress and generate an event 'MoveUp' on object 'myAlien' with the call:- rasieEvent( 'MoveUp', 'myAlien', 'Game' ); (it's worth noting that this can be done in C++ and in script, allowing you to raise any event on any object at any time).

The event reaches the event handler of the 'myObject' and goes one of two ways. First it looks for the presence of a scripted method that is based on the event name and the object id, in this case myObject_MoveUp. If this function isn't found, it'll then look for a scripted function based on the entity class id and the event name, in this case Alien_MoveUp. If this isn't found, the event goes nowhere and the game continues.

This allows for use cases; first, you can effectively build 'classes' in script by providing event methods based on the class name and the event. Every single entity that is an instance of the Alien entity class will have the chance to call Alien_MoveUp when it's called. This allows you to script a generic behaviour for the class, so all 'basic' Aliens will act the same. From here you can specialise certain entities; so imagine you wanted one of your aliens to drop a powerup. You would simply create a scripted method override for a specific event (eg: 'Die') and add the special code in there.

Because it's all 100% scripted, you can specialise any entity in the game by just adding a scripted method. I will be expanding the system to allow 'named event functions', so the user can specify a named function to use as the event handler. This would allow a group of entities with different classes to share the same behaviour for certain actions. There's a good chance that this specialisation will be applicable at both class and object level, although this makes things a little more complicated. One final addition I might make is to give the entity classes the ability to be inherited from. This would effectively open up a huge inheritance tree of possible events and further specialisation of entity classes; so a class called 'SuperAlien' could be derived from 'Alien' which behaves a lot like alien, except it maybe moves faster or shoots more. Like the previous situation, the complexity of the event lookups will start growing exponentially, but with a little script function caching we could keep the same speed - perhaps even boosting it from the current implementation.
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now