Welcome to the Builder Academy

Question clanedit in who

More
16 May 2016 23:22 #5900 by thomas
Replied by thomas on topic clanedit in who
yes. This state is never saved, so rearranging the list can just be done to your liking.

Please Log in or Create an account to join the conversation.

More
16 May 2016 23:26 - 16 May 2016 23:27 #5901 by JTP
Replied by JTP on topic clanedit in who
And if i dont rearrange them, and the olc line is broken. Then what happends ?
Last edit: 16 May 2016 23:27 by JTP.

Please Log in or Create an account to join the conversation.

More
17 May 2016 00:32 #5902 by thomas
Replied by thomas on topic clanedit in who
then, people in the GET_PROTOCOL and QRACE states are shown on the who list.

Please Log in or Create an account to join the conversation.

More
17 May 2016 07:28 - 17 May 2016 20:53 #5904 by JTP
Replied by JTP on topic clanedit in who
Ok done, thanks for that.

Then im trying to add Clanname to the who list, after players title:
Code:
} else { "", GET_LEVEL(tch), RACE_ABBR(tch), CLASS_ABBR(tch), GET_NAME(tch), (*GET_TITLE(tch) ? " " : ""), GET_TITLE(tch), CLANNAME(tch), <--added clanname CCNRM(ch, C_SPR)); }
Code:
When i make i get: act.informative.c:1576: error: request for member ‘title’ in something not a structure or union send_to_char(ch, "%s\tm[ %2d %s %s ]\tn %s%s%s%s (%s)", <--added (%s) If i use PLAYERCLAN(tch) instead of CLANNAME(tch), then when i make i get: act.informative.c:1577: warning: format ‘%s’ expects type ‘char *’, but argument 10 has type ‘int’

Whats up ?
Last edit: 17 May 2016 20:53 by JTP.

Please Log in or Create an account to join the conversation.

More
17 May 2016 20:38 #5906 by thomas
Replied by thomas on topic clanedit in who
I think this may be a good time to write a little about preprocessors and structures.

When you compile your code, three things happen in order:
1. the preprocessor substitutes any preprocessor macros. Those are the #define lines.
2. the compiler compiles each file with the preprocessed code to object files.
3. the linker combines the object files to an executable.

You error comes from the second step, but is caused by not doing the first step right.


When we have a C preprocessor statement like
Code:
#define CLANNAME(clan) ((clan).title)
and you then use it like this:
Code:
CLANNAME(tch)
it will be translated by the preprocessor to
Code:
((tch).title)
But tch is a pointer to a char_data structure, and dereferencing it with a '.' will not work. See stackoverflow.com/a/2575050
This results in trying to look up the "title" member in the pointer (not on the structure) and thus gives you your first error. Another problem here is that since tch is a char_data structure, you can't use it directly here - since you need a clan structure.
So, you try to look it up using PLAYERCLAN(tch) instead. Apparently, this returns a number. This text should give you a hint about that:

#define PLAYERCLAN(ch) ((ch)->player_specials->saved.clannum)

This then gives you your other warning - you're trying to write out to the %s format identifier, but are supplying a number.

So to the solution. I think there's at least one macro missing:
Code:
#define GET_CLAN(num) (clan_index[(num)])

Then you can do it like this:
Code:
CLANNAME(GET_CLAN(PLAYERCLAN(tch)))
Which the preprocessor will turn into
Code:
(((clan_index[((tch)->player_specials->saved.clannum)])).title)
which should compile. The amount of parenthesises here is not important - they will be ignored, generally.

However, there's a catch here. What if a person isn't in a clan? Then, probably, the clannum will be negative or 0? If it is negative, you have an issue, and need to check it before using it. If it is 0, make sure clan 0 makes sense as "no clan".

Please Log in or Create an account to join the conversation.

Time to create page: 0.206 seconds