Stupidest question ever!

Posted by Rayze on Thu 24 Oct 2002 02:38 AM — 9 posts, 32,937 views.

#0
I'm trying to put in the damage snippet, so I go to Fight.c and add in the following code,
else
{
sprintf( buf1, "$n's %s %s $N%c", attack, vp, dam, punct);
sprintf( buf2, "Your %s %s $N%c", attack, vp, dam, punct);
sprintf( buf3, "$n's %s %s you%c", attack, vp, dam, punct);
}

I save, compile, etc...

I keep getting an else error or something...
Australia Forum Administrator #1
So why did you put "else" there?
#2
Nope, not the Stupidest Question.

I think I have you beat a million times over.
#3
When I take out the else I get the following error message though:

C:\source\smaug1.4a\src\fight.c(4257) : error C2449: found '{' at file scope (missing function header?)
C:\source\smaug1.4a\src\fight.c(4261) : error C2059: syntax error : '}'


How do I fix that? I'm a total newbie at this...
USA #4
like nick i dont see where the else comes into play.. but the code i use for when dt isnt barehand or poison is

sprintf( buf1, "$n's %s %s $N%c (%d)", attack, vp, punct, dam );
sprintf( buf2, "Your %s %s $N%c (%d)", attack, vp, punct, dam );
sprintf( buf3, "$n's %s %s you%c (%d)", attack, vp, punct, dam );

so one problem is that you dont have the %d for your damage. after the ""'s it places the the values from the variables and places them in %s/%c/%d etc., s is string d is for numbers and i would assume c is for charecters like ./,';..

the way you have it set up
sprintf( buf1, "$n's %s %s $N%c", attack, vp, dam, punct);
there is no place for the damage to be placed.. so to follow your layout you would want like
sprintf( buf1, "$n's %s %s $N %d%c", attack, vp, dam, punct);
although then the puncution (.) will be after the damage

this may be part of problem but i would think there is something else wrong to or you would have gotten a different error. id suggest starting with a clean new_dam_message and just replace the 3 of the msgs with new ones, always easy to start over ;)
Australia Forum Administrator #5
OK, sounds like the code is in the wrong place. The two errors you get (wrong else, or { at file scope), suggests you are "outside" a function.

eg. this would do it.


int myfunction (int a)
  {
  int b;

  b = a * 5;
  return b;

  }  // this is the end of the function

// code below is outside any function

else
  {
  b = 22;
  }

#6
Thanks for the help... got it to work.
#7
Is this a snippet to show how much damage your dealing/receiving, and if it is where in fight.c do you put it?
Australia Forum Administrator #8
Judging by the error messages further up, it would go at around line 4257 (roughly).