To make global, or not to make global

Started by
0 comments, last by WitchLord 12 years, 11 months ago
Hello:
I guess my subject may not be the most descriptive; I am really not sure how to explain this.

First, I'll give a bit of a rundown on my setup. Every object that will appear in game inherits an Entity object. Players, npcs, bullets, etc etc. Now, events are handled by a public EventManager object that is defined on Entity. This EventManager is also defined on the World class, as well as a couple other places where things will take place and objects will need to be notified of them.

This leads me to a question. I am working to set up scripting, and I was told that a global script would probably be best, (which makes sense; it'd save a lot of overhead). So my idea was to set the scripting up so that the entrypoint would be passed the object it is being called on. This would allow the script to register functions as events to be called when that event is invoked. This works, but I see a potential issue; if I am using global functions and I define an Enter function to be called when a player enters a room for example, I will not be able to define another Enter function.

Is there another way around this? I am new to game development, so advice here would be really appreciated.
If code is needed, my engine can be found at:
http://code.google.com/p/aspenmud.
Thanks,
Advertisement
It's hard to say what would be best for your project, as every project has different needs.

In my opinion, a global script that has all the game logic is NOT the way to go. Sure, it might be easier to write the script where all functions, objects can directly see and interact with each other, but it can be harder to modularize the game.

I'm a fan of the design where each object has it's own script, where the script implements just what concerns that object. Objects that interact with others should do so through formal interfaces so that they don't really need to know the details of the other objects. This way of doing it will allow you to easily substitute modules on the fly without having to reload the entire script for all objects at all times.

However, if you prefer to go with a global script, then you need to solve your dilemma by using different names, e.g. by prepending the name of room to the function, like room1_enter, room2_enter, etc. Or, you can use classes where the class name is the name of the room.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement