12 Sep, 2006, Brinson wrote in the 1st comment:
Votes: 0
The codebase I've chosen has a monk class which has different anatomies it must study in order to fight them with acceptable proficiency. These anatomies are assigned by race, but the mud doesn't have a system to determine what race a mob/player is, so I thought I'd try and code on, and so I wrote this:

if (IS_GOOD(ch))
{
if (IS_GOOD(victim))
sendf(ch, "This %s greets you warmly.\n\r", victim->pcdata->race);
else if (IS_NEUTRAL(victim))
sendf(ch, "This %s looks very disinterrested.\n\r", victim->pcdata->race);
else sendf(ch, "This %s grins at you evilly.\n\r", victim->pcdata->race);
}
else if (IS_NEUTRAL(ch))
{
if (IS_GOOD(victim))
sendf(ch, "This %s beams a smile at you.\n\r", victim->pcdata->race);
else if (IS_NEUTRAL(victim))
sendf(ch, "This %s looks just as disinterrested as you.\n\r", victim->pcdata->race);
else sendf(ch, "This %s grins at you evilly.\n\r", victim->pcdata->race);
}
else
{
if (IS_GOOD(victim))
sendf(ch, "This %s smiles, hoping you will turn from your evil path.\n\r", victim->pcdata->race);
else if (IS_NEUTRAL(victim))
sendf(ch, "This %s looks very disinterrested.\n\r", victim->pcdata->race);
else sendf(ch, "This %s grins evilly with you.\n\r", victim->pcdata->race);
}



but victim->pcdata->race isn't being recognized. When I consider I get like:

The perfect match!
This looks just as disinterrested as you.
Brinson is about the same size as you.

Any idea why?

BTW, it is acceptable for me to discuss code problems on this forum, right?
12 Sep, 2006, kiasyn wrote in the 2nd comment:
Votes: 0
It is in the 'coding discussions' group, so I'd say so.
12 Sep, 2006, Zeno wrote in the 3rd comment:
Votes: 0
Use gdb, print victim->pcdata->race.

Are you sure that you shouldn't be printing victim->pcdata->race->name?
13 Sep, 2006, Davion wrote in the 4th comment:
Votes: 0
If you're using stock rom, then ch->race is an integer. What you want to use is
race_table[ch->race].name

Also, in ROM, race is in the char_data structure, not the pc_data one, so you'll have to show us some mods. And yes, this is very appropriate. See no reason for it to be anywhere else ;)
13 Sep, 2006, Brinson wrote in the 5th comment:
Votes: 0
Zeno said:
Use gdb, print victim->pcdata->race.

Are you sure that you shouldn't be printing victim->pcdata->race->name?


I tried name, didn't work…now about the other suggestion…I am pretty newbish coder…just learning…could you explain that a bit more?
13 Sep, 2006, Brinson wrote in the 6th comment:
Votes: 0
Davion said:
If you're using stock rom, then ch->race is an integer. What you want to use is
race_table[ch->race].name

Also, in ROM, race is in the char_data structure, not the pc_data one, so you'll have to show us some mods. And yes, this is very appropriate. See no reason for it to be anywhere else ;)


I love you. It worked. Thank you so much.
13 Sep, 2006, Valcados wrote in the 7th comment:
Votes: 0
This is a type of thing that as a coder you can eventually develop some intuition about. Suppose that, as you originally thought, race name was stored on the individual character. That would mean if you had 100 Elves log on, the MUD would have to allocate 100 separate blocks of memory and store the word "Elf" in each one :devil:. Even if the MUD has advanced string hashing like SMAUG so that this would be avoided, it would still take more space on many systems to store a char * than to store an int, and even that's assuming the name of the race is the ONLY thing stored on the player. It makes far more sense to maintain a single table with all the race related stuff, and merely store a table index (an int) on the individual players. As you get better and better, things like this will eventually become very clear to you so that when you decide to check something race-related, you'll instantly know there's a table lookup, or something similar, involved :smile:
0.0/7