#1 Members - Reputation: 196
Posted 14 February 2013 - 03:16 PM
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?
#2 Members - Reputation: 163
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 Crossbones+ - Reputation: 5144
Posted 14 February 2013 - 03:42 PM
For this specifically, don’t add a bunch of parameters to the functions.Some of my functions have 12 parameters, and it is annoying and unelegant to add new features.
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.
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
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums
#4 Members - Reputation: 196
Posted 14 February 2013 - 03:44 PM
Although i think i will try the data structure idea, thanks L spiro
#5 Crossbones+ - Reputation: 5144
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
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
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums






