Jump to content
  • Advertisement
Sign in to follow this  

To make global, or not to make global

This topic is 2563 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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:

Share this post

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


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!