15 Dec, 2011, thecircuitbox wrote in the 1st comment:
Votes: 0
So instead of the crappy -1000 to 1000 in showing in the score i wanted to do something more vivid.
I do not want to change the alignment code itself just the way it is displayed in score.

Here is what I come up with.
if (GET_ALIGNMENT(ch) <= 502 && GET_ALIGNMENT(ch) >= 1000)
send_to_char(ch, " Alignment : Chaotic Good \r\n");
if (GET_ALIGNMENT(ch) <= 102 && GET_ALIGNMENT(ch) >= 501)
send_to_char(ch, " Alignment : Lawful Good \r\n");
if (GET_ALIGNMENT(ch) <= 101 && GET_ALIGNMENT(ch) >= -101)
send_to_char(ch, " Alignment : Neutral \r\n");
if (GET_ALIGNMENT(ch) <= -102 && GET_ALIGNMENT(ch) >= -501)
send_to_char(ch, " Alignment : Lawful Evil \r\n");
if (GET_ALIGNMENT(ch) <= -502 && GET_ALIGNMENT(ch) >= -1000)
send_to_char(ch, " Alignment : Chaotic Evil \r\n");


But it does not show the good alignments only the negative ones; neutral also works. This code could be smaller but I am new.
So any ideas on why it would do it?

Below is the full ACMD(do_score)
do_score
15 Dec, 2011, Ssolvarain wrote in the 2nd comment:
Votes: 0
thecircuitbox said:
So instead of the crappy -1000 to 1000 in showing in the score i wanted to do something more vivid.
I do not want to change the alignment code itself just the way it is displayed in score.

Here is what I come up with.
if (GET_ALIGNMENT(ch) <= 502 && GET_ALIGNMENT(ch) >= 1000)
send_to_char(ch, " Alignment : Chaotic Good \r\n");
if (GET_ALIGNMENT(ch) <= 102 && GET_ALIGNMENT(ch) >= 501)
send_to_char(ch, " Alignment : Lawful Good \r\n");


So any ideas on why it would do it?


If alignment is less than 502 and alignment is greater than 1000.
If alignment is less than 102 and alignment is greater than 501.

I think you might have something backwards thar.
15 Dec, 2011, thecircuitbox wrote in the 3rd comment:
Votes: 0
LOL they need to be switched. let me try it.

//EDIT: Seems to work now thank you.
15 Dec, 2011, Rarva.Riendf wrote in the 4th comment:
Votes: 0
I also suggest you use stuff like ALIGN_MAX_GOOD ALIGN_MIN_GOOD etc instead of hard coded value, so if you want to change the range later, or even use those value in spells or in other places, you dont have to remember where they are used.
10 Jan, 2012, thecircuitbox wrote in the 5th comment:
Votes: 0
I am a cut and paste coder so, that seems a bit out of my range.
10 Jan, 2012, David Haley wrote in the 6th comment:
Votes: 0
That should not be out of your range, it's just adding some simple constants. If it is out of your range, then you should do that homework ASAP because you won't go anywhere really if you don't know how to use something like that.
10 Jan, 2012, arholly wrote in the 7th comment:
Votes: 0
+1 on what David said. It's OK to say you start out that way, but if you ask people to explain things when you need help, you'll learn and be able to do more.
10 Jan, 2012, Hades_Kane wrote in the 8th comment:
Votes: 0
thecircuitbox said:
I am a cut and paste coder so, that seems a bit out of my range.


I code in ROM, so it might be different in circle… but here is how I would do that in ROM…

The 'merc.h' file is included in basically -every- C file throughout the codebase, and in many places in that file you have what is referred to as a "constant" declared.

For example, you might have something like MAX_LEVEL = 120; declared in the file. Anywhere else in the code where I need to calculate something based off of MAX_LEVEL, then I just use that instead of "120." The reason we do this is because, let's say you have 38 instances of needing to calculate something based off of what your game's max level is, and then for one reason or another, you guys decide to change the max level. Well, now you have to sift through your code to find all 38 places you used the "120" value and change that. If you have MAX_LEVEL declared in your code, and all 38 instances use "MAX_LEVEL" instead of "120" then you -only- have to change that value one time, rather than in 38 places. You go into merc.h, change the "MAX_LEVEL" value from 120 to 130 or whatever, and voila, after you do a clean compile, the value is good to go in every other spot.

So in the case of alignment?

I might do something like this:

#define  ALIGN_MAX_C_GOOD     1000
#define ALIGN_MIN_C_GOOD 500
#define ALIGN_MAX_L_GOOD 449
#define ALIGN_MIN_L_GOOD 250
#define ALIGN_MAX_NEUTRAL 249
#define ALIGN_MIN_NEUTRAL -249
#define ALIGN_MIN_L_EVIL -250
#define ALIGN_MAX_L_EVIL -449
#define ALIGN_MIN_C_EVIL -500
#define ALIGN_MAX_C_EVIL -1000


Values are just an estimation.

if (GET_ALIGNMENT(ch) <=ALIGN_ MAX_C_GOOD && GET_ALIGNMENT(ch) >= ALIGN_MIN_C_GOOD)
send_to_char(ch, " Alignment : Chaotic Good \r\n");
if (GET_ALIGNMENT(ch) <= ALIGN_MAX_L_GOOD && GET_ALIGNMENT(ch) >= ALIGN_MIN_L_GOOD)
send_to_char(ch, " Alignment : Lawful Good \r\n");
if (GET_ALIGNMENT(ch) <= ALIGN_MAX_NEUTRAL && GET_ALIGNMENT(ch) >= ALIGN_MIN_NEUTRAL)
send_to_char(ch, " Alignment : Neutral \r\n");
if (GET_ALIGNMENT(ch) <= ALIGN_MAX_L_EVIL && GET_ALIGNMENT(ch) >= ALIGN_MIN_L_EVIL)
send_to_char(ch, " Alignment : Lawful Evil \r\n");
if (GET_ALIGNMENT(ch) <= ALIGN_MAX_C_EVIL && GET_ALIGNMENT(ch) >= ALIGN_MIN_C_EVIL)
send_to_char(ch, " Alignment : Chaotic Evil \r\n");


I'm at work and doing this in a hurry, so I'm not claiming this to be exactly accurate, but it should be enough to give you an idea. Also, some of the values could easily be taken out and the code simplified a little, but I was just using the code you supplied for the sake of time.

Doing this can and usually will save you a lot of time and headaches in the future, and as a copy/paste coder, you should be able to look at things like MAX_LEVEL or LEVEL_HERO or things like that to see working examples of how this is done.
10 Jan, 2012, thecircuitbox wrote in the 9th comment:
Votes: 0
Any example code i should look at for the constants?

//EDIT: I did not refresh before posting so I missed a post.

I see what you mean and understand. By putting in a define with levels I can use those defines throughout any file if that file includes the #include file.h so I can have that align in any file.c.

While I goofing around and searching I found this:

#define IS_GOOD(ch)    (GET_ALIGNMENT(ch) >= 350)
#define IS_EVIL(ch) (GET_ALIGNMENT(ch) <= -350)
#define IS_NEUTRAL(ch) (!IS_GOOD(ch) && !IS_EVIL(ch))
11 Jan, 2012, arholly wrote in the 10th comment:
Votes: 0
Yes, that is pretty much what he is saying. It is often easy to put them in the twilight.h file if you are going to use it globally/universally.
12 Jan, 2012, Hades_Kane wrote in the 11th comment:
Votes: 0
thecircuitbox said:
Any example code i should look at for the constants?

//EDIT: I did not refresh before posting so I missed a post.

I see what you mean and understand. By putting in a define with levels I can use those defines throughout any file if that file includes the #include file.h so I can have that align in any file.c.

While I goofing around and searching I found this:

#define IS_GOOD(ch)    (GET_ALIGNMENT(ch) >= 350)
#define IS_EVIL(ch) (GET_ALIGNMENT(ch) <= -350)
#define IS_NEUTRAL(ch) (!IS_GOOD(ch) && !IS_EVIL(ch))


Awesome, glad I could help clear it up. You should have no problem using those, and that's a good template for you to build upon if you want to add different levels of good/evil.
13 Jan, 2012, JohnnyStarr wrote in the 12th comment:
Votes: 0
The do_score() function is so bloated to begin with. Macros are great and all, but some
object oriented design might really save you trouble down the road; especially when it comes
to debugging.

Even if you are using vanilla C, you can still follow an OOP pattern to handle some of these
issues:

/* character.c */

static const char* ch_alignment(CHAR_DATA *ch) {
/* handle alignment output */
}

const char* ch_display(CHAR_DATA *ch) {
char *buf = ch_alignment(ch);

/* grab any other values and append to output buffer */

return buf;
}


Obviously, theres a lot more you can do here than just display score data. I'm not saying
that you have to re-write your codebase to follow a strict paradigm - although ROM could use
it. I just think that macros aren't the answer. ROM is big enough as it is without adding
more bloat.

PS: I in no way am putting down Hades_Kane's suggestion itself. Just expressing a different approach.
13 Jan, 2012, Hades_Kane wrote in the 13th comment:
Votes: 0
JohnnyStarr said:
The do_score() function is so bloated to begin with. Macros are great and all, but some
object oriented design might really save you trouble down the road; especially when it comes
to debugging.

Even if you are using vanilla C, you can still follow an OOP pattern to handle some of these
issues:

/* character.c */

static const char* ch_alignment(CHAR_DATA *ch) {
/* handle alignment output */
}

const char* ch_display(CHAR_DATA *ch) {
char *buf = ch_alignment(ch);

/* grab any other values and append to output buffer */

return buf;
}


Obviously, theres a lot more you can do here than just display score data. I'm not saying
that you have to re-write your codebase to follow a strict paradigm - although ROM could use
it. I just think that macros aren't the answer. ROM is big enough as it is without adding
more bloat.

PS: I in no way am putting down Hades_Kane's suggestion itself. Just expressing a different approach.


As someone who described themselves as a "cut and paste coder" and was initially concerned that macros was out of his range, I figured just addressing the direct issue he was concerned with would be the best approach for him :p

As newbie coders get more adept, certainly things like that ought to be given some consideration, but I think it's also important to consider to try to keep advice within the skill range of the person seeking it. I've seen some posts around here where someone new to coding asks something relatively simple and are bombarded with loads of high-end suggestions and such. As someone who not long ago was in a similar spot, it can be a bit overwhelming to be presented with advanced mechanics when you are still working on understanding the basics.
14 Jan, 2012, thecircuitbox wrote in the 14th comment:
Votes: 0
Yeah i thought i could do something like
ACMD(do_score)
{
const char* align2[ch]= {
if (GET_ALIGNMENT(ch) <= 502 && GET_ALIGNMENT(ch) >= 1000)
send_to_char(ch, "Chaotic Good\r\n");
if (GET_ALIGNMENT(ch) <= 102 && GET_ALIGNMENT(ch) >= 501)
send_to_char(ch, "Lawful Good\r\n");
if (GET_ALIGNMENT(ch) <= 101 && GET_ALIGNMENT(ch) >= -101)
send_to_char(ch, "Neutral\r\n");
if (GET_ALIGNMENT(ch) <= -102 && GET_ALIGNMENT(ch) >= -501)
send_to_char(ch, "Lawful Evil\r\n");
if (GET_ALIGNMENT(ch) <= -502 && GET_ALIGNMENT(ch) >= -1000)
send_to_char(ch, "Chaotic Evil\r\n");
}

send_to_char(ch, "Alignment: %d\r\n", align2[ch] );

}


But I never got it to work so I used an easier method. And yeah I do not understand that OOP pattern.
14 Jan, 2012, Runter wrote in the 15th comment:
Votes: 0
What rationale would lead you to believe that this code would work? What should it even do?

const char* align2[ch]= {
if (GET_ALIGNMENT(ch) <= 502 && GET_ALIGNMENT(ch) >= 1000)
send_to_char(ch, "Chaotic Good\r\n");
if (GET_ALIGNMENT(ch) <= 102 && GET_ALIGNMENT(ch) >= 501)
send_to_char(ch, "Lawful Good\r\n");
if (GET_ALIGNMENT(ch) <= 101 && GET_ALIGNMENT(ch) >= -101)
send_to_char(ch, "Neutral\r\n");
if (GET_ALIGNMENT(ch) <= -102 && GET_ALIGNMENT(ch) >= -501)
send_to_char(ch, "Lawful Evil\r\n");
if (GET_ALIGNMENT(ch) <= -502 && GET_ALIGNMENT(ch) >= -1000)
send_to_char(ch, "Chaotic Evil\r\n");
}
15 Jan, 2012, thecircuitbox wrote in the 16th comment:
Votes: 0
I literally had no idea and was just taking bit and pieces of code and trying to make it work. The code get align and then be a I do not know the name but act as an argument when i use the %s/d variable.
0.0/16