Solved How to setup #define values the right way?

Question that is answered or resolved.

Bruce

Active member
Hello everyone,

I am seeing different methods to set it up from go_bys, and I always have questions about them in my mind.
I do know they all work, but it's best for me to learn the right way at the beginning rather than copy and paste the code.
Therefore, I have 4 methods below, can someone please help me understand which method is the right way?

Method 1:
in updated.c
Code:
#define    TITLE_TEXT 1        //1
#define    CURSORSPR1 2        //2
#define    CURSORSPR2 3        //3
#define    CURSORSPR3 4        //4


Method 2:
in updated.c
Code:
#include "data/scripts/common/constants.c"
constants.h
Code:
#define    TITLE_TEXT 1        //1
#define    CURSORSPR1 2        //2
#define    CURSORSPR2 3        //3
#define    CURSORSPR3 4        //4
#define A_ATKUP                     openborconstant("ANI_ATTACKUP")
#define A_ATKBACK                 openborconstant("ANI_ATTACKBACKWARD")
#define A_BLOCK                     openborconstant("ANI_BLOCK")
#define A_BLOCKP                   openborconstant("ANI_BLOCKPAIN")
#define A_BLOCKP2                 openborconstant("ANI_BLOCKPAIN2")
Since I have other defined variables inside constants.h already. Wouldn't this method be better?


Method 3:
in updated.c
Code:
#include "data/scripts/common/constants.c"
constants.h
Code:
#include "data/scripts/common/MenuConstants.c"
#define A_ATKUP                     openborconstant("ANI_ATTACKUP")
#define A_ATKBACK                 openborconstant("ANI_ATTACKBACKWARD")
#define A_BLOCK                     openborconstant("ANI_BLOCK")
#define A_BLOCKP                   openborconstant("ANI_BLOCKPAIN")
#define A_BLOCKP2                 openborconstant("ANI_BLOCKPAIN2")
MenuConstants.c
Code:
#define    TITLE_TEXT 1        //1
#define    CURSORSPR1 2        //2
#define    CURSORSPR2 3        //3
#define    CURSORSPR3 4        //4

Method 4:
in updated.c
Code:
#include "data/scripts/common/MenuConstants.c"

I am sorry for the noob questions and thank you for your help,
god bless you all!
 
Solution
I am seeing a bunch of go_bys using them, and I like these shortcuts because of less messy in the coding.

I don't know what a "go_by" is, but since I was the very first person to utilize constants and the #define directive in OpenBOR script, I can promise I have a lot more experience with it than they do. The point of a #define is to create named constants or macros out of something that is normally ambiguous.

The problem with doing that to openborconstant() is that it's already a constant. You're actually adding ambiguity. Eventually, you will end up with a lot of spaghetti code dependencies and hard to track bugs.

Since you have not mentioned or explained which method is better, I assume, all...
@Bruce

Do NOT use #define to rename or shortcut openborconstant(). That absolutely WILL come back to bite you later. Trust me, I know from experience. Get rid of those right now.

As for the rest, you have the right idea. (y)

DC
 
@Bruce

Do NOT use #define to rename or shortcut openborconstant(). That absolutely WILL come back to bite you later. Trust me, I know from experience. Get rid of those right now.

As for the rest, you have the right idea. (y)

DC
I am seeing a bunch of go_bys using them, and I like these shortcuts because of less messy in the coding.
However, your advises are priceless, so I will remove all these defines of my game.
Since you have not mentioned or explained which method is better, I assume, all methods are the same as far as performance and memory concerns,

Thank you very much
 
I am seeing a bunch of go_bys using them, and I like these shortcuts because of less messy in the coding.

I don't know what a "go_by" is, but since I was the very first person to utilize constants and the #define directive in OpenBOR script, I can promise I have a lot more experience with it than they do. The point of a #define is to create named constants or macros out of something that is normally ambiguous.

The problem with doing that to openborconstant() is that it's already a constant. You're actually adding ambiguity. Eventually, you will end up with a lot of spaghetti code dependencies and hard to track bugs.

Since you have not mentioned or explained which method is better, I assume, all methods are the same as far as performance and memory concerns,

#defines don't use memory at all. The methodology is about what is most organized and easier to understand later. In other words, it depends on the rest of your code.

DC
 
Solution
Back
Top Bottom