16 Jul, 2011, arholly wrote in the 1st comment:
Votes: 0
Hello. I'm trying to revise the dump command to show the race of the mob when it creates the dump so I can check the race of the mob vs. the description to at least make sure they are close. But I cannot figure it out.

fprintf(fp,"\nMobile Analysis\n");
fprintf(fp, "—————\n");
fprintf(fp, "VNUM-COUNT-KILLED-RACE-SHORT DESC\n");
nMatch = 0;
for (vnum = 0; nMatch < top_mob_index; vnum++)
if ((pMobIndex = get_mob_index(vnum)) != NULL)
{
nMatch++;
fprintf(fp,"#%-4d-%3d active-%3d killed-race-%s\n",
pMobIndex->vnum,pMobIndex->count,
pMobIndex->killed,pMobIndex->short_descr);
}
fclose(fp);


I just can't figure out what the code for doing the race name should be. I've tried looking at other pieces of code, but it never seems to work? What should it be and why?

Thanks,
Arholly
17 Jul, 2011, JohnnyStarr wrote in the 2nd comment:
Votes: 0
I think it's something like:

printf("%s", race_table[ch->pcdata->race]);


of course, "race_table" is named something else. Check out tables.c, I think it's there.
If I was on my laptop I would check for you. The idea is that the pcdata structure stores an integer that corresponds with the
race table. CHEERS
17 Jul, 2011, arholly wrote in the 3rd comment:
Votes: 0
I get this then…
db.c: In function do_dump:
db.c:3362: error: PC_DATA has no member named race
17 Jul, 2011, plamzi wrote in the 4th comment:
Votes: 0
It's most likely race_table[ch->race].race_name. But you don't have to guess such things. Just find the place where the race table and pc data structures are defined. It's usually in an .h file called something like "structs.h".
18 Jul, 2011, arholly wrote in the 5th comment:
Votes: 0
Thanks. It ended up being race_table[ch->race].name. Thanks for the help.
18 Jul, 2011, arholly wrote in the 6th comment:
Votes: 0
Errrr…OK, now I'm running into a problem. It's listing every mob as human instead of their intended race. Any thoughts?
18 Jul, 2011, Omega wrote in the 7th comment:
Votes: 0
try not using ch's race…. As do_dump is a command, so ch is your character, use the appropriate value for the loop and it should sort out the problem.

Unless I am completely mistaken, if you change your race, it will dump everyone as that race….. But I digress.

example:

race_table[pMobIndex->race].name

instead of

race_table[ch->race].name

19 Jul, 2011, plamzi wrote in the 8th comment:
Votes: 0
Darien said:
try not using ch's race…. As do_dump is a command, so ch is your character…


It's good to understand how this works. The "do_something" functions are declared via a macro which always maps "ch" to the doer of the command. Find where that macro is defined and you'll see the arguments that a do_something function always takes.
19 Jul, 2011, arholly wrote in the 9th comment:
Votes: 0
And pMobIndex is what then? An index of the mobs?
19 Jul, 2011, Runter wrote in the 10th comment:
Votes: 0
arholly said:
And pMobIndex is what then? An index of the mobs?


It's the template that npcs are created from. One structure is the template (the mob_index_data) and another is the actual npc in memory. Probably like char_data. In any event, it just copys stuff from the index usually or it shares it with a pointer to the mob_index_data.
19 Jul, 2011, Omega wrote in the 11th comment:
Votes: 0
The biggest thing you should do, as a programmer, is read your code; first and foremost.

ie:

fprintf(fp,"\nMobile Analysis\n");
fprintf(fp, "—————\n");
fprintf(fp, "VNUM-COUNT-KILLED-RACE-SHORT DESC\n");
nMatch = 0;
for (vnum = 0; nMatch < top_mob_index; vnum++)
if ((pMobIndex = get_mob_index(vnum)) != NULL)
{
nMatch++;
fprintf(fp,"#%-4d-%3d active-%3d killed-race-%s\n",
pMobIndex->vnum,pMobIndex->count,
pMobIndex->killed,pMobIndex->short_descr);
}
fclose(fp);


if your printing the race out in that above loop (thats your own code posted back)
then you should see that pMobIndex->(variable) is being called.

your do_dump should look like this.


void do_dump(CHAR_DATA *ch, char *argument) {

….


so you should be able to tell that ch is indeed the caller of the command.

As for it being a MACRO which was another person's post, some muds have indeed made it a macro. COMMAND(do_dump) { or whatever, but it too would define CHAR_DATA *ch.


But I digress. The point is, my biggest suggestion to you is to read your code; read, read, read your code. And if you don't understand what you read, ie, the pointers/variable usage/naming, then its time to read a book or two on the language.
20 Jul, 2011, arholly wrote in the 12th comment:
Votes: 0
Thanks Darien. It's just been a while since I've worked on a mud doing any program. I had one I worked on years ago, but it's been a while and I'm starting from scratch again. Thanks for the help and clarification. I appreciate it.
21 Jul, 2011, Omega wrote in the 13th comment:
Votes: 0
No problem, sorry if I came across alittle snarky was trying to hit home the fact that people need to read their code. Most code related questions on this forum that I've seen could be simply answered by people reading their code and actually understanding it.

But thats not here, nor there. I hope all goes well with your development; and do feel free to hit me up anytime via pm if you got any questions or problems. I pretty much whore out of my programming knowledge to those who ask nicely :)

Cheers.
21 Jul, 2011, Rarva.Riendf wrote in the 14th comment:
Votes: 0
Considering most of your questions are pretty much understanding values problem I suggest you use an IDE that shows your variables value while running step by step.
I use Eclipse with Cygwin on Windows, and to validate the code before I put it on the server I also use Eclipse on a Fedora, so I can run Valgrind (Eclipse has a nice plugin for it) as well.
And always compile with -Wall -ggdb, and latest version of GCC.
It should help you tremendously when you do not understand why a value you think shoudl be there is not.
0.0/14