Welcome to the Builder Academy

Question how can fight.c call diag_char_to_char?

More
05 Nov 2012 03:01 #983 by wifidi
Dear tbaMUD,
I'd like to call act.informative.c's diag_char_to_char from fight.c. The only difference in fight.c is showing "You" versus "GET_NAME(ch)/someone/an immortal" so it hardly needs to be fully written out twice. I'll pay tbaMUD tuition to learn function scope. Otherwise I have to wait until it comes up in class or magically dawns on me.
'Preciate it,
wifidi
p.s. - I steadily notice the code I'm actually adding getting smaller and smaller, which means I'm becoming a better C programmer.

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

More
05 Nov 2012 03:09 #984 by Liko

wifidi wrote: Dear tbaMUD,
I'd like to call act.informative.c's diag_char_to_char from fight.c. The only difference in fight.c is showing "You" versus "GET_NAME(ch)/someone/an immortal" so it hardly needs to be fully written out twice. I'll pay tbaMUD tuition to learn function scope. Otherwise I have to wait until it comes up in class or magically dawns on me.
'Preciate it,
wifidi
p.s. - I steadily notice the code I'm actually adding getting smaller and smaller, which means I'm becoming a better C programmer.

Code:
diag_char_to_char(vict, ch);

You would have to change vict and ch to what your code is calling. Make sure act.h is defined to be included also.

Randian(0.0.0)
Owner/Developer

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

More
05 Nov 2012 14:18 #989 by wifidi
fight.c:
#include "act.h"
...
for (ch = world[IN_ROOM(victim)].people; ch; ch = ch->next_in_room)
if (!IS_NPC(ch) && PRF_FLAGGED(ch, PRF_MELEE_HEALTH_MSGS)
&& (ch == victim || FIGHTING(ch) == victim || FIGHTING(ch) == FIGHTING(victim)))
diag_char_to_char(victim, ch);
gcc:
fight.c:607: undefined reference to `diag_char_to_char'

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

More
05 Nov 2012 15:00 - 05 Nov 2012 15:39 #990 by wifidi
I'll track down send_to_char() since that function seems callable from anywhere. Beginners want everything accessible everywhere. The programming class I'm in is covering functions now. Maybe the concept of scope in programming becomes challenging in a similar way to the story of Solomon and the baby. "What file is the baby's Mom? And who gets the baby." etc.
Newbs with good ideas, in my case one of CoffeeMUD's, are sometimes bound to write unnecessary lines of code then crawl back onto a forum or site seeking the key to programming as well as an expert or insisting they have a new, awesome MUD. I don't see anything awesome about having to define essentially the same function in act.informative.c, in fight.c. I could cheat and include a header file with the code, yet the point is avoiding redundancy, clarity, efficiency, etc., instead of a program twice as long as another that produces the same result. The tbaMUD admins have either thought of nearly all the basics or implented them. Therefore being unable to call a function from somewhere should serve as a warning re: its intended scope.
Last edit: 05 Nov 2012 15:39 by wifidi. Reason: finishing the comment

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

More
05 Nov 2012 16:49 #991 by Liko

wifidi wrote: I'll track down send_to_char() since that function seems callable from anywhere. Beginners want everything accessible everywhere. The programming class I'm in is covering functions now. Maybe the concept of scope in programming becomes challenging in a similar way to the story of Solomon and the baby. "What file is the baby's Mom? And who gets the baby." etc.
Newbs with good ideas, in my case one of CoffeeMUD's, are sometimes bound to write unnecessary lines of code then crawl back onto a forum or site seeking the key to programming as well as an expert or insisting they have a new, awesome MUD. I don't see anything awesome about having to define essentially the same function in act.informative.c, in fight.c. I could cheat and include a header file with the code, yet the point is avoiding redundancy, clarity, efficiency, etc., instead of a program twice as long as another that produces the same result. The tbaMUD admins have either thought of nearly all the basics or implented them. Therefore being unable to call a function from somewhere should serve as a warning re: its intended scope.


Opps, sorry for my last post. I was half asleep and gave you a half answer. Anyway its quite easy to fix.

1. Open act.h and search act.informative.c and find this line:
Code:
void free_recent_players(void);

Under it add:
Code:
void diag_char_to_char(struct char_data *i, struct char_data *ch);

2. close act.h

3. Open act.informative.c and find this line
Code:
static void diag_char_to_char(struct char_data *i, struct char_data *ch);

and change it to this:
Code:
void diag_char_to_char(struct char_data *i, struct char_data *ch);

Now search diag_char

and change this line :
Code:
static void diag_char_to_char(struct char_data *i, struct char_data *ch)

to
Code:
void diag_char_to_char(struct char_data *i, struct char_data *ch)

4. Close act.informative.c and compile.

Static voids are simple meant to be found in only one file. By making a void you can have it called from other files also.

I hope this helps.

Randian(0.0.0)
Owner/Developer

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

More
06 Nov 2012 02:16 #993 by wifidi
Dear Liko,
Thanks a million. I'll stop posting unoptimized code until I can code the streamlined version of the idea in question. In the end, if two code segments achieve the same goal yet one takes less memory and CPU..., etc. I began thinking I'm good enough to teach how to code and now see I have too much to learn yet. I look forward to being a more substantial contributor.

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

Time to create page: 0.226 seconds