27 Apr, 2010, mijutsai wrote in the 1st comment:
Votes: 0
Sooo, i've got everything in, almost everything compiles and I can't seem to figure out where I went wrong here.

Quote
gcc -c -ggdb -Wall -O fight.c
fight.c: In function xp_compute:
fight.c:2454: error: bonus undeclared (first use in this function)
fight.c:2454: error: (Each undeclared identifier is reported only once
fight.c:2454: error: for each function it appears in.)
fight.c:2458: error: buf undeclared (first use in this function)
fight.c:2459: error: expected ) before ; token
fight.c:2460: error: invalid use of void expression
fight.c:2460: error: expected ; before } token
make: *** [fight.o] Error 1


Here are the lines of code its happening in:

bonus = xp;

if (double_exp)
{
sprintf (buf, "`!You receive `^%d`! experience due to double experience.`x\n\r",
send_to_char (buf, gch );
}


any ideas? Oh and before you ask, my color code uses ` instead of { that was something converted a long time ago. And has no bearing on what i'm putting in.
27 Apr, 2010, Mudder wrote in the 2nd comment:
Votes: 0
Did you try commenting that out and see if it compiles?

This isn't the problem but \r\n is more correct than \n\r.
27 Apr, 2010, Zeno wrote in the 3rd comment:
Votes: 0
Quote
sprintf (buf, "`!You receive `^%d`! experience due to double experience.`x\n\r",

That doesn't look right. The uh, end. You copied it correctly?
27 Apr, 2010, mijutsai wrote in the 4th comment:
Votes: 0
yeah only thing that is wrong with that is at the end of the color code instead of `x it should of been `` but the ` is what is used in my code for color instead of { all the `^ and `! is color code. And I know that at the end there should of been a small bit that should of been there. But now. I get.

Quote
gcc -c -ggdb -Wall -O fight.c
fight.c: In function xp_compute:
fight.c:2454: error: bonus undeclared (first use in this function)
fight.c:2454: error: (Each undeclared identifier is reported only once
fight.c:2454: error: for each function it appears in.)
fight.c:2458: error: buf undeclared (first use in this function)
make: *** [fight.o] Error 1


bonus = xp;
(thats line 2454)
sprintf (buf, "`!You receive `^%d`! experience due to double experience``\n\r", bonus );

thats line 2458

ugh this shouldnt be happening. I ripped it straight from the other version of this code. The code i'm putting it into is an earlier one that I i'm revamping and scrapping the other one.
27 Apr, 2010, Kayle wrote in the 5th comment:
Votes: 0
mijutsai said:
Quote
gcc -c -ggdb -Wall -O fight.c
fight.c: In function xp_compute:
fight.c:2454: error: bonus undeclared (first use in this function)
fight.c:2454: error: (Each undeclared identifier is reported only once
fight.c:2454: error: for each function it appears in.)
fight.c:2458: error: buf undeclared (first use in this function)
make: *** [fight.o] Error 1


It's telling you what's wrong. You didn't declare the variables (In most cases at the top of the function). You just start using them.
27 Apr, 2010, Runter wrote in the 6th comment:
Votes: 0
Let me qualify this with saying you didn't post the full code, and some of it looks pasted incorrectly, so it's hard for any of us to say what is wrong beyond a pretty good guess.

All that being said—I don't want to be rude, or discourage anyone from seeking help here, but I think it behooves me to point this out. "error: `bonus' undeclared (first use in this function)" If you want to know what is wrong, like Kayle said, it's probably "'bonus' is undeclared".
27 Apr, 2010, mijutsai wrote in the 7th comment:
Votes: 0
Oh by no means am I offended. I just figured it would be easy to just post that section of code only since thats the only part that was giving me issues. The code itself inlays inside of act_wiz.c and of course merc.h, as well as fight.c and update.c. I'm just having trouble on where I should be defining 'bonus' at. I've put it in before, its just been so dang long that I don't remember where I initially put it at in the other source. lol.

Forgive me for seeming half retarded bout this, like I said i'm rusty as all heck and this is why i'm getting back into this so that I can refresh myself on it all again.
27 Apr, 2010, Kayle wrote in the 8th comment:
Votes: 0
mijutsai said:
I'm just having trouble on where I should be defining 'bonus' at. I've put it in before, its just been so dang long that I don't remember where I initially put it at in the other source. lol.


You put it at the top of the function where the offending lines are located.
27 Apr, 2010, Sharmair wrote in the 9th comment:
Votes: 0
You will normally declare variables at the top of the most local scope the variable
is used in. In this case they are used only in the xp_compute function, so the top
of that function would be a good place. The variable bonus should be an int and
buf a char buffer (array of char) large enough to hold the longest string you will
store in it. It is normal practice in MERC derived muds to have buffers like this
defined as MAX_STRING_LENGTH, though in this case even 100 would be plenty.
So, at the top of xp_compute(), you should add something like:
int bonus;
char buf[MAX_STRING_LENGTH];
27 Apr, 2010, quixadhal wrote in the 10th comment:
Votes: 0
Yep, declaring the variable is the problem, as pointed out.

And, just because this has cropped up several times again recently, "\n\r" is totally wrong and causes subtle problems for many mud clients, ranging from triggers not working properly, to screen formatting being broken. The TELNET spec states that line endings need to be "\r\n" (CRLF).

The argument people always try to use is that every codebase out there does it that way, and they can't all be wrong, can they? Yes. They can. The original Diku authors did it wrong, and since everybody just copied them, they also mimic'd this wrong behavior. Even a few non-Diku codebases do this, because the authors worked on DikuMUD's at some point and picked up that bad habit.

So, I know it's a pain, but it only takes a half hour or less to do a global search/replace on all your code to flip the line ending characters around so they're correct. Most of your players won't care, you may not care, but you may find people NOT complaining about broken clients quite as often.
27 Apr, 2010, KaVir wrote in the 11th comment:
Votes: 0
quixadhal said:
The argument people always try to use is that every codebase out there does it that way, and they can't all be wrong, can they?

One argument I heard a few times was that it's so common in muds that that some clients also decided to do it the other way around as a sort of unofficial mud standard, which meant that "correct" implementations would sometimes run into problems.

I've never been able to track down the source of this claim, and I can't say that I've ever encountered any problems with any of the clients I've used (for either "\n\r" or "\r\n"), so I suspect it may just be an urban legend (perhaps started by a mix-up with IAC GA, or just a bad implementation?). But for quite a long time I intentionally wrote it the wrong way around, simply because I was worried about client compatibility.
27 Apr, 2010, mijutsai wrote in the 12th comment:
Votes: 0
Thanks Sharmair. I figured it out once I got my buddy to im me back this morning and I just put the
char buf[MAX_STRING_LENGTH];
in there and it compiled just fine, I knew I was missing something just wasnt quite sure what it was
Thanks everyone for their input.
Random Picks
0.0/12