Using Global Variables

From TDN

Contents

Original Question:

Do you have to use global variables to define players and objects in T2D?



Answer:

As has been said above, globals, particularly when starting/prototyping, are just convenient.

More production-quality games would want to ensure that objects are stored in containers and that when the game/mission finishes, these containers and their contents are destroyed.

You can lookup SimSets/SimGroups in the TGE engine doco for an idea on how to maintain abstract lists of objects.

The good thing about T2D is that when you add any of its objects to the scene (fxSceneGraph2D), they are automatically destroyed when the scene is destroyed and so the scene can be used as a container.

With singular objects like a $player, it's much easier to simply use a global although when networking comes along, this practice won't scale very well.

Also, I personally don't like wide-scale use of naming objects e.g. "new fxCoolObject2D(MyNamedObject)" because of the potential of naming conflicts. This is particularly true for the naming of GUI elements which don't have the concept of instantiation when placed onto the canvas.

- Melv