Sign in to follow this  
sorressean

To make global, or not to make global

Recommended Posts

sorressean    103
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,

Share this post


Link to post
Share on other sites
WitchLord    4678
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this