20 Dec, 2012, triskaledia wrote in the 1st comment:
Votes: 0
sprintf(buf, "%ld\n\r", race_table[ch->race].aff);
stc(buf, ch);


Simple enough. Obviously, though, the output to the character is the affects in bit form.

I located the define for bits:
char *affect_bit_name (int vector)
if (vector & AFF_SPELLNAME) strcat (buf, " spellstring");

Tried doing:
sprintf(buf, "%ld\n\r", race_table[ch->race].aff[affect_bit_name]);
stc(buf, ch);

Compile didn't like that statement: error: subscripted value is neither array nor pointer

I was kind of suprised I couldn't find a snippet for this, any help appreciated. When I wake up tomorrow,
I'll keep playing around with it.
20 Dec, 2012, Igabod wrote in the 2nd comment:
Votes: 0
gotta look it up by gsn_lookup or something like that I believe to get it to display the name not the bit
20 Dec, 2012, Tyche wrote in the 3rd comment:
Votes: 0
affect_bit_name is a function that takes an integer and returns a pointer to a string.

sprintf(buf, "%s\r\n", affect_bit_name(race_table[ch->race].aff));
21 Dec, 2012, triskaledia wrote in the 4th comment:
Votes: 0
For future reference, that worked greatly. Thank you.
Now onto the coding aspects of it.
In order to properly code that, one would use the function, select the table,
point to the proper array part of the table, and hope for the best?
function(table_name[table_variable_call].table_array_name) ?
I might not have the proper names there, but is this a general concept of how it works?
21 Dec, 2012, Tyche wrote in the 5th comment:
Votes: 0
triskaledia said:
For future reference, that worked greatly. Thank you.
Now onto the coding aspects of it.
In order to properly code that, one would use the function, select the table,
point to the proper array part of the table, and hope for the best?
function(table_name[table_variable_call].table_array_name) ?
I might not have the proper names there, but is this a general concept of how it works?


I'm not sure exactly where to start. It's all about pointer arithmetic and types.
Some C syntax tends to obscure what is actually going on and the exact order of evaluation.
It certainly is deterministic, I mean there's no hoping involved. ;-)

Given that…
a->b is the same as (*a).b
and…
p[q] is the same as *(p+q)

This is equivalent.
sprintf(buf, "%s\r\n", affect_bit_name((*(race_table + (*ch).race)).aff));

Do these conversions help? It should clarify the evaluation order of the expressions.

Here's a sample program.
#include <stdio.h>

struct foo {
int a;
int b;
};

struct foo fooarray[3] = {
{1,2},{3,4},{5,6}
};

int main() {
printf("fooarray[2].b = %d\n",fooarray[2].b);
printf("(*(fooarray + 2)).b = %d\n",(*(fooarray + 2)).b);
}


Or maybe understanding the operator precedence in C

() [] . -> * are higher precedence than the mathematical operators

So..
sprintf(buf, "%s\r\n", affect_bit_name(race_table[ch->race].aff));

ch->race —> integer (used as subscript)
race_table[ch->race] —> race_type struct
race_table[ch->race].aff —–> integer (used as bitfield)
affect_bit_name(race_table[ch->race].aff) —-> char * (returned from function)
sprintf(buf, "%s\r\n", affect_bit_name(race_table[ch->race].aff))
0.0/5