Game Development Community

Resolved-Register an event

by Christian Rademan · in Torque Game Builder · 09/06/2007 (11:14 pm) · 6 replies

I am new to Torque and can't find the info I am looking for.
I want to know how to register an event with the event manager and how to register a listener for that event.
A code example would be great!
Is there any docs I could read about this?
About how TGB handles events?

#1
09/07/2007 (12:30 am)
Given that you don't have a source license (as far as I can tell anyway), your only real options are to work within the existing event reporting system, which are called "callbacks". In your documentation, you should find a list of all callbacks that are provided by the engine, and can code your project around those.

Behaviors for example are all callback driven, and allow you to group small sets of functionality that react to events from the underlying engine in a cohesive manner.

Finally, specifically for input event handling, the ActionMap system allows direct function binding to any input even (keyboard, mouse, joystick) that the operating system provides, and you may want to research that system as well.

The callbacks that are available from the underlying engine are pretty complete, and are designed specifically to allow a very large majority of games to be written completely in TorqueScript, without having to deal with the underlying c++ source code at all.
#2
09/07/2007 (12:53 am)
Ok. I understand, but the Eventmanager has these two functions.

registerEvent(String event)
Description: Register an event with the event manager.
Params:
event: The event to register. Return:
Whether or not the event was registered successfully.


subscribe(SimObject listener, String event, String callback)
Description: Subscribe a listener to an event.
Params:
listener: The listener to subscribe.
event: The event to subscribe to.
callback: Optional method name to receive the event notification. If this is not specified, "on[event]" will be used. Return:
Whether or not the subscription was successful.

How are they used? Can I register my game objects to listen for specific events?
#3
09/07/2007 (1:08 am)
For example.
Say I have an atomic bomb or something and when It explodes I want all the other objects in the scene to explode.
How do I manage that?
#4
09/07/2007 (3:26 am)
As you know when you call the destruction / explosion code of the bomb you can simple go through all objects in your scene and destroy them by calling their "explode routine" or however you have called it. (like t2dSceneObject::explode(%this) { } )
#5
09/07/2007 (4:25 am)
Thanks.
I still want some more information about the eventmanager.See my post above.
What are those functions for?
#6
05/15/2011 (5:24 pm)
Another example of event subscription would be that the user has buttons on screen to purchase items he can afford, like in StarCraft.

When the user's gold is updated, it sends a custom event to the system, for instance "goldUpdated". Any object that is purchasable can subscribe for this event and, upon receiving it, check the new gold amount and adjust its on-screen button as purchasable or not.

This would keep me from having to search every object in the scene for my buttons and adjusting them manually. That is, an observer pattern seems very useful for games. I'm guess that an observer pattern is not provided?

Thanks.