lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On 30 Dec '05, at 7:05 AM, John Klimek wrote:

For my game I plan to have lots of objects running scripts (players,

npcs, rooms, items, etc).  Whenever an object runs a script I create a

global lua userdata called "Entity".

Using globals is usually bad form, unless the object really is global in scope. In this case it sounds like the better thing to do is to make the scripts define functions that are methods on the entity object. (Or almost equivalently, register functions that will be called by particular types of entities, passing the entity as a parameter.)

The lua script can then check for the actual entity type by using Entity:GetType.

Again checking the type of an object at runtime is often not the best design. If the script functions were entity methods, then each function would apply to a particular type of entity and it wouldn't need to check the type.

Have you looked at MOO (an object-oriented MUD language) and its LambdaCore library? These would be excellent sources of design ideas for implementing this type of environment. So would interactive-fiction languages like INFORM. This particular wheel has been invented many times over, so take advantage of what's already been worked out!