Jump to content

  • Log In with Google      Sign In   
  • Create Account


Want improve the flow of my game


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 game of thought   Members   -  Reputation: 212

Like
0Likes
Like

Posted 14 February 2013 - 03:16 PM

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?

Sponsor:

#2 GKANG   Members   -  Reputation: 163

Like
0Likes
Like

Posted 14 February 2013 - 03:34 PM

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?..



#3 L. Spiro   Crossbones+   -  Reputation: 12299

Like
3Likes
Like

Posted 14 February 2013 - 03:42 PM

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, 14 February 2013 - 03:47 PM.

It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#4 game of thought   Members   -  Reputation: 212

Like
0Likes
Like

Posted 14 February 2013 - 03:44 PM

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

#5 L. Spiro   Crossbones+   -  Reputation: 12299

Like
0Likes
Like

Posted 14 February 2013 - 03:50 PM

Since I edited my posted just after your reply and you probably missed it, be sure to look back on it for the link and the tips within.

 

 

L. Spiro


It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS