Sign in to follow this  
game of thought

Want improve the flow of my game

Recommended Posts

I have written a rather large text combat game(>600 lines) with no oo or anything, just functions.

It works fine however i would like to streamline the code a lot. Some of my functions have 12 parameters, and it is annoying and unelegant to add new features.

I do realise i could just use globals but i have a nasty feeling they are like #define in c. What can i do(without just importing some form of data structure or dict) to streamline this code?

Share this post


Link to post
Share on other sites
GKANG    165

It's hard to say without seeing any code or knowing what exactly you have going into the functions. As a guess though, you could make an Actor class, so each object of that class could be a monster or party member. Then you'd just send in the object by reference to the functions and you have all of those stats / items / etc in just one argument.

 

I'm not sure what else you'd be sending in?..

Share this post


Link to post
Share on other sites
L. Spiro    25621
Obviously, going object-oriented is generally a good decision, but without knowing anything else about your game there is nothing more to say on that topic.

Some of my functions have 12 parameters, and it is annoying and unelegant to add new features.

For this specifically, don’t add a bunch of parameters to the functions.
Add a structure as a parameter and pass it as a reference. It is quite easy to add new data to the structure when you want to send more to the function.


There are a ton of other things to consider listed here: http://lspiroengine.com/?p=126
Especially the “Structure” section.


L. Spiro Edited by L. Spiro

Share this post


Link to post
Share on other sites
The problem with using an actor class is that i would have to completely re design the game and i would not like to do that. Plus it works fine already. I would like to avoid oop if that is possible.

Although i think i will try the data structure idea, thanks L spiro

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