How do I comment stuff out?

Posted by ShadowGazer on Tue 10 Feb 2009 07:15 AM — 10 posts, 30,862 views.

USA #0
I'm quite new to SMAUG programming and I would like to know how to comment things out in the code? I'm trying to add custom slay messages and it says to comment out do_slay in fight.c, how do I do that? I've tried all sorts of ways but everything gives me errors when I re compile.

Here is the errors I am getting:

fight.c
fight.c:4435: syntax error before '{' token
fight.c:4440: warning: type defaults to `int' in declaration of `argument'
fight.c:4440: `arg' undeclared here (not in a function)
fight.c:4440: warning: passing arg 1 of `one_argument' from incompatible pointer type
fight.c:4440: warning: initialization from incompatible pointer type
fight.c:4440: initializer element is not constant
fight.c:4440: warning: data definition has no type or storage class
fight.c:4441: warning: type defaults to `int' in declaration of `one_argument'
fight.c:4441: warning: parameter names (without types) in function declaration
fight.c:4441: conflicting types for `one_argument'
mud.h:5454: previous declaration of `one_argument'
fight.c:4441: warning: data definition has no type or storage class
fight.c:4442: syntax error before "if"
fight.c:4469: syntax error before string constant
fight.c:4470: syntax error before string constant
fight.c:4476: syntax error before numeric constant
fight.c:4477: syntax error before numeric constant
fight.c:4483: syntax error before string constant
fight.c:4484: syntax error before string constant
fight.c:4485: syntax error before string constant
fight.c:4486: syntax error before string constant
fight.c:4487: syntax error before string constant
fight.c:4493: syntax error before numeric constant
fight.c:4494: syntax error before numeric constant
fight.c:4500: syntax error before numeric constant
fight.c:4501: syntax error before numeric constant
fight.c:4507: syntax error before numeric constant
fight.c:4508: syntax error before numeric constant
fight.c:4514: syntax error before string constant
fight.c:4515: syntax error before string constant
fight.c:4518: warning: type defaults to `int' in declaration of `set_cur_char'
fight.c:4518: warning: parameter names (without types) in function declaration
fight.c:4518: conflicting types for `set_cur_char'
mud.h:5416: previous declaration of `set_cur_char'
fight.c:4518: warning: data definition has no type or storage class
fight.c:4519: warning: type defaults to `int' in declaration of `raw_kill'
fight.c:4519: warning: parameter names (without types) in function declaration
fight.c:4519: conflicting types for `raw_kill'
fight.c:3557: previous declaration of `raw_kill'
fight.c:4519: warning: data definition has no type or storage class
fight.c:4520: syntax error before "return"
make[1]: *** [fight.o] Error 1
make[1]: Leaving directory `/home/m049kev/smaug1.8/src'
make: *** [all] Error 2

Can someone explain what I'm doing wrong?
Australia Forum Administrator #1
To comment one line:


// --- Everything after // is a comment


To comment out a batch:


/*

Everything is a comment until:

*/


Note that block comments don't nest, so if there is */ inside the code you are commenting out you will have problems.

Probably a more reliable way is this:


#if 0

.... code to be commented out.

#endif


The line "#if 0" is a conditional compilation directive that always is false, so effectively everything between it and "#endif" is not processed.

USA #2
I tried using the #if 0 and #endif statements, and still got an error when I went to compile.

fight.c
fight.c:4468: syntax error before "if"
fight.c:4471: syntax error before string constant
fight.c:4472: syntax error before string constant
fight.c:4478: syntax error before numeric constant
fight.c:4479: syntax error before numeric constant
fight.c:4485: syntax error before string constant
fight.c:4486: syntax error before string constant
fight.c:4487: syntax error before string constant
fight.c:4488: syntax error before string constant
fight.c:4489: syntax error before string constant
fight.c:4495: syntax error before numeric constant
fight.c:4496: syntax error before numeric constant
fight.c:4502: syntax error before numeric constant
fight.c:4503: syntax error before numeric constant
fight.c:4509: syntax error before numeric constant
fight.c:4510: syntax error before numeric constant
fight.c:4516: syntax error before string constant
fight.c:4517: syntax error before string constant
fight.c:4520: warning: type defaults to `int' in declaration of `set_cur_char'
fight.c:4520: warning: parameter names (without types) in function declaration
fight.c:4520: conflicting types for `set_cur_char'
mud.h:5416: previous declaration of `set_cur_char'
fight.c:4520: warning: data definition has no type or storage class
fight.c:4521: warning: type defaults to `int' in declaration of `raw_kill'
fight.c:4521: warning: parameter names (without types) in function declaration
fight.c:4521: conflicting types for `raw_kill'
fight.c:3557: previous declaration of `raw_kill'
fight.c:4521: warning: data definition has no type or storage class
fight.c:4522: syntax error before "return"
make[1]: *** [fight.o] Error 1
make[1]: Leaving directory `/home/m049kev/smaug1.8/src'
make: *** [all] Error 2

Here is the code I am trying to comment out. Did I do it right?

#if 0
void do_slay( CHAR_DATA *ch, char *argument )
{
CHAR_DATA *victim;
char arg[MAX_INPUT_LENGTH];
char arg2[MAX_INPUT_LENGTH];

argument = one_argument( argument, arg );
one_argument( argument, arg2 );
if ( arg[0] == '\0' )
{
send_to_char( "Slay whom?\n\r", ch );
return;
}

if ( ( victim = get_char_room( ch, arg ) ) == NULL )
{
send_to_char( "They aren't here.\n\r", ch );
return;
}

if ( ch == victim )
{
send_to_char( "Suicide is a mortal sin.\n\r", ch );
return;
}

if ( !IS_NPC(victim) && get_trust( victim ) >= get_trust( ch ) )
{
send_to_char( "You failed.\n\r", ch );
return;
}
#endif
USA #3
Please show exactly where line 4468 is in fight.c.
USA #4
if ( !str_cmp( arg2, "immolate" ) )

That is line 4468
USA #5
That line wasn't in the code you posted. So, the problem isn't coming from what you did with commenting, or at least not the part you showed us. You'll need to figure out why there's a syntax error at that line; it might help to have more context.

FWIW you did the commenting of that function correctly. :-)
USA #6
if ( !str_cmp( arg2, "immolate" ) )
{
act( AT_FIRE, "Your fireball turns $N into a blazing inferno.", ch, NULL, victim, TO_CHAR );
act( AT_FIRE, "$n releases a searing fireball in your direction.", ch, NULL, victim, TO_VICT );
act( AT_FIRE, "$n points at $N, who bursts into a flaming inferno.", ch, NULL, victim, TO_NOTVICT );

Here is a bit more code, I hope this helps. Please be aware that I really have no idea what I'm doing when it comes to coding, I'm new at this so when you say I need to figure out where the syntax error is coming from, I'm completely lost. I hope someone can help!
USA #7
Generally a syntax error occurs in previous lines, and causes subsequent lines to generate errors. It would seem that you've changed something that broke something, and didn't undo it correctly. Anyhow, the lines before that if statement are the ones you want to be looking at.

EDIT:
note that it might be safer to go back to a fresh copy that doesn't have any other such surprises in it :-)
Amended on Tue 10 Feb 2009 09:35 PM by David Haley
Australia Forum Administrator #8
The message was:

Quote:

fight.c
fight.c:4468: syntax error before "if"


Since the error was before the if, you really want to show (say), 5 lines before, and after it.

I repeat comments I have made earlier to other beginner coders:

Quote:
The problem with tackling modifying server code, when you are not experienced in C or C++ is going to be a long, frustrating road, if you don't understand the basics of C programming.

You will find some time spent on simpler C programs, getting to grips with the basics of memory allocation, pointers, setting up linked lists, string manipulation, and stuff like that, well rewarded as it will give you the basis to understand a MUD server.

I suggest finding some books (or web sites) which give some C tutorials, and get some general practice. This will also help you understand compiler error messages, and runtime error messages, so you will know the difference between normal and abnormal.


Modifying a MUD server is hard enough, but if you are unsure of basics like how to turn a line of code into a comment, you will find it much easier if you go over the basics with some tutorial programs. MUD servers extensively use things like dynamic memory allocation, and "state machines" which allow the server to react in a minute to something which is happening now.

There are lots of great books on C programming, and also try Googling for "learn c tutorial" or something similar.
USA #9
Ok, I restored the backup I had and gave up. I'll read up on some books before I edit any more code. Thanks for all the suggestions and help guys!