Grouping Objects and Callbacks
by Orion the Hunter · in Torque Game Builder · 05/31/2013 (5:36 pm) · 6 replies
Hi,
I've been trying to figure out groups but I can't really figure it out. Is there a way for the game to call a function when a certain group from a certain scenegraph dies? Alternatively, I could just make them be part of a class or something but I'd prefer to test out the group thingy right near "layer."
I've been trying to figure out groups but I can't really figure it out. Is there a way for the game to call a function when a certain group from a certain scenegraph dies? Alternatively, I could just make them be part of a class or something but I'd prefer to test out the group thingy right near "layer."
#2
06/07/2013 (8:38 am)
Hmm... event manager. I'm not quite sure how one would go about making that. I looked it up in the docs, but I can't tell what it does and when it does it... if that makes sense. I'm trying to make it so that when Drill1, Drill2, Drill3, and Drill4 die, the object, "ShopKeeper," comes down from his ledge and opens the shop (which can be accomplished with the "setPosition" function, though so there's no problem there).
#3
That's the basic setup.
now you can do this:
Any sim object that is subscribed as above will recieve notification and the specified function will be called.
06/07/2013 (11:07 am)
function initializeGameEventManager()
{
if (!isObject(GameEventManager))
{
$GameEventManager = new EventManager(GameEventManager)
{
queue = "GameEventManager";
};
// Module related signals
GameEventManager.registerEvent("_DrillDied");
}
if (!isObject(GameListener))
{
$GameListener = new ScriptMsgListener(GameListener)
{
class = "GameEventListener";
};
// Module related subscriptions
GameEventManager.subscribe(GameListener, "_DrillDied", "onDrillDied");
}
}
// Cleanup the GameEventManager
function destroyGameEventManager()
{
if (isObject(GameEventManager) && isObject(GameListener))
{
// Remove all the subscriptions
GameEventManager.remove(GameListener, "_DrillDied");
// Delete the actual objects
GameEventManager.delete();
GameListener.delete();
// Clear the global variables, just in case
$GameEventManager = "";
$GameListener = "";
}
}
function GameEventListener::onDrillDied(%this, %msgData)
{
// Do stuff here
}That's the basic setup.
now you can do this:
GameEventManager.subscribe(%mySimObject, "_DrillDied", "onDrillDied");
// ...
function mySimObjectClass::onDrillDied(%this, %msgData)
{
// do stuff when a drill dies - see below, second parameter is %msgData
}
// ... When a drill dies post the event:
GameEventManager.postEvent("_DrillDied", %dyingDrill);Any sim object that is subscribed as above will recieve notification and the specified function will be called.
#4
06/07/2013 (11:25 am)
Thanks! :D Sorry... I feel like such a fool, but what's a sim object again?
#5
So, just about anything that you use in your game can subscribe to events.
06/07/2013 (6:34 pm)
Base class - sprite, trigger, pretty much everything used in a scene is derived from SimObject.So, just about anything that you use in your game can subscribe to events.
#6
06/08/2013 (8:48 am)
Ah, thanks! I'll try it out.
Torque Owner Richard Ranft
Roostertail Games