Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ SMAUG ➜ Compiling the server ➜ How do I comment stuff out?

How do I comment stuff out?

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by ShadowGazer   USA  (17 posts)  Bio
Date Tue 10 Feb 2009 07:15 AM (UTC)
Message
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?
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #1 on Tue 10 Feb 2009 08:19 AM (UTC)
Message
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.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by ShadowGazer   USA  (17 posts)  Bio
Date Reply #2 on Tue 10 Feb 2009 08:41 PM (UTC)
Message
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
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #3 on Tue 10 Feb 2009 08:52 PM (UTC)
Message
Please show exactly where line 4468 is in fight.c.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by ShadowGazer   USA  (17 posts)  Bio
Date Reply #4 on Tue 10 Feb 2009 09:11 PM (UTC)
Message
if ( !str_cmp( arg2, "immolate" ) )

That is line 4468
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #5 on Tue 10 Feb 2009 09:14 PM (UTC)
Message
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. :-)

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by ShadowGazer   USA  (17 posts)  Bio
Date Reply #6 on Tue 10 Feb 2009 09:21 PM (UTC)
Message
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!
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #7 on Tue 10 Feb 2009 09:34 PM (UTC)

Amended on Tue 10 Feb 2009 09:35 PM (UTC) by David Haley

Message
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 :-)

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #8 on Tue 10 Feb 2009 10:40 PM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by ShadowGazer   USA  (17 posts)  Bio
Date Reply #9 on Tue 10 Feb 2009 10:56 PM (UTC)

Amended on Tue 10 Feb 2009 11:20 PM (UTC) by ShadowGazer

Message
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!
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


23,587 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.