Jump to content
  • Advertisement
Sign in to follow this  
Victor Chavauty

How can i make objects have completely different outcomes?

This topic is 1474 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

Hi! I was wondering the following: Lets suppose we have a game in which the main character can acquire different items. Lets suppose some of these items increase health or mana. That is not hard at all to accomplish, but now let's suppose that we want to add a new item, an item that can teletransport you to another place. Well, that is a whole new block of code to add. Now if we wanted to add another item that makes you fly, this would change a lot more things, like, for example, the animation of your character. Well, as items add up, the code gets more and more complex and confusing. Now, since i am a complete begginer in the field, i am only able to think of a few methods to do such a thing. I could, for example, make so that an item would be able to do all of possible reactions, but i would configure each one (possibly with boolean values) so that they only do what they are meant to do. But this would make the code heavy, because each item, or object, would have to load all possible outcomes. So i was wondering if there is a more elegant way to achieve what i am talking about. I thought that maybe adding a Script engine to the game would work, but since, as stated previously, i am a complete begginer, i have never even tried to implement a script engine in a game. Would it work? Would i be able to program each item separately?


I am new to this forum, so if i am breaking any rule by posting this question here please warn me and i will remove it.


Thank you very much for your answer.


Edit: An Example of such a system would be Binding of Isaac, as some items completely change some aspects of the game.


Another possible example would be: Imagine i can have a lot of different companions in the game, just like Binding of Isaac, but each one move differently. Using an script engine, would i be able to program each companian with the different maths that would describe his movement? Otherwise, as i said before, the only way i can imagine doing so would to make all possibilities available to a companion, and only define as "true" the one which i desire.

Edited by Victor Chavauty

Share this post

Link to post
Share on other sites

So i was wondering if there is a more elegant way to achieve what i am talking about

There's no simple answer to this question.


I think, most game are planned with some major features in mind (a feature, which will require the support of the underlying engine), like flying entities or unique AI behavior. Then the game designer will try to design the game around this major features. If they desire some new feature, they often will try to use the available stuff first(you will be surprised, how much you can archive with a few fixed game features). Often you can get away with some compromise, instead of flying entites, you could use a long jump entity with an similar gameplay effect for example.


Eventually, but rather seldomly, some major feature will be added to let the designers create new behavior/effects. But, as you already said, adding a major feature is often really difficult and therefor embedded in a major game update, an addon or even the next release in a series.




I thought that maybe adding a Script engine to the game would work

A scripting engine is more of a designer tool then a major feature. A scripting engine will help your game designer to access the game features more easily and to prototype some game design more rapidly, therefor it is a very useful addition to a game (!). But it will not add new major features to the game, that is the difference. If your engine only supports moving entities on a 2d plane in a 3d environment, a scripting engine will not allow you suddently to have a free 3d roaming environment.

Edited by Ashaman73

Share this post

Link to post
Share on other sites



What I understand is that your trying to add new behaviour to items without creating a large item class filled up with boolean flags indicating which behaviours the item owner has.


When I had to create a system for random item properties (Extra Damage, % Damage increase) I came up with the idea of using the decorator design pattern which allows you to create new item behaviour without the construction of deep hierachies and large classes. (http://en.wikipedia.org/wiki/Decorator_pattern


Maybe you want to take a look at this pattern.


You could have some kind of MagicItem class which has a reference to its owner and a method which can manipulate his owner (Add new skills or stats). Now this method can be overriden by the decorating items which can add additional behaviour or complete new behaviour.


The method could make something like this:

owner.skillset.addSkill(new FlyingAbility());


Hope this helps.


Best Regards

Edited by Olaf Van Schlacht

Share this post

Link to post
Share on other sites

I See! Thanks both of you for your answers. I will be sure to give the Decorator pattern a try, but i still think a script engine would be something pretty interesting to add, plus it can't hurt.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!