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
➜ SMAUG coding
➜ life bar
It is now over 60 days since the last post. This thread is closed.
Refresh page
Pages: 1
2
| Posted by
| Conner
USA (381 posts) Bio
|
| Date
| Reply #15 on Tue 05 Jun 2007 06:28 AM (UTC) |
| Message
| Well, yes, but only a fool thinks he knows it all and refuses an opportunity to further his education when presented rather than blunder blindly. ;)
Yes, C++ and C will both get upset at you when you try to compile if you don't declare a variable to start with, but I didn't notice any variables in his example that weren't declared, I take it that you did? (I also hadn't actually tried it myself either yet.)
I hope that you'll remember to let us know the results of your trial. ;) |
-=Conner=-
--
Come test your mettle in the Land of Legends at telnet://tcdbbs.zapto.org:4000
or, for a little family oriented medieval fun, come join us at The Castle's Dungeon BBS at telnet://tcdbbs.zapto.org
or, if you just want information about either, check our web page at http://tcdbbs.zapto.org | | Top |
|
| Posted by
| David Haley
USA (3,881 posts) Bio
|
| Date
| Reply #16 on Tue 05 Jun 2007 06:33 AM (UTC) |
| Message
|
Quote: but recently I find out that if you do not declare the variables in the top of the function, c++ will get an error. No; strict C will get upset, but C++ won't. But as Conner says, in any case you need to declare the variable somewhere. (I much prefer C++'s flexibility of letting you declare it where it's relevant.)
If the code I gave you doesn't compile I'd be curious to hear what compiler you're using. I'm using gcc 4.1.2 and it compiles fine; if anything the newer versions are more strict and if it compiles here it should compile on previous versions too. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | | Top |
|
| Posted by
| Alkarindil
Brazil (70 posts) Bio
|
| Date
| Reply #17 on Tue 05 Jun 2007 05:14 PM (UTC) Amended on Tue 05 Jun 2007 05:16 PM (UTC) by Alkarindil
|
| Message
| I use Microsoft Visual C++ 6.
I doesn't mean to say that the variables were not declared. I said that in my C++ compiler it *must* be declared in the top! I don't know why! But all the time I declare a variable in the middle of the function, it returns me an error.
For example:
//--
int value(int A, int B){
int C; //in the top
C = A+A;
int D; //in the middle (here is the problem)
D = C+B;
return D;}
//--
It doesn't work.
//--
int value(int A, int B){
int C;
int D;
C = A+A;
D = C+B;
return D;}
//--
Work!
=D | | Top |
|
| Posted by
| Meerclar
USA (733 posts) Bio
|
| Date
| Reply #18 on Tue 05 Jun 2007 06:55 PM (UTC) |
| Message
| | That's seriously odd because I just compiled your code with D in the middle without a hitch. Are you absolutely certain you don't have strict/explicit declaration options enabled? |
Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org | | Top |
|
| Posted by
| David Haley
USA (3,881 posts) Bio
|
| Date
| Reply #19 on Tue 05 Jun 2007 09:25 PM (UTC) |
| Message
| C++ even in MSVS6 does not require variables to be declared at the top by default. I know that for a fact because I have done it over and over again.
It is possible that it is entering C mode in MSVS6 because it sees that your file is .c. Try making it .cpp and seeing what it does. Or tell it to compile in C++ mode -- that's in the options somewhere. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | | Top |
|
| Posted by
| Alkarindil
Brazil (70 posts) Bio
|
| Date
| Reply #20 on Wed 06 Jun 2007 08:55 PM (UTC) |
| Message
| David, I think you're right!
I will reinstall MSVS6, my system is having problems because of a virus. Then I will do it. But I believe it is the file as you said! | | Top |
|
| Posted by
| Alkarindil
Brazil (70 posts) Bio
|
| Date
| Reply #21 on Tue 12 Jun 2007 07:27 PM (UTC) Amended on Tue 12 Jun 2007 07:43 PM (UTC) by Alkarindil
|
| Message
| Hi everyone!
Here is the last code I've done.
It's optimized and it's working!
Enjoy!
//--------------------------
/*
Bar Drawning by Alkarindil
Example to print a life bar:
bar_draw(ch->hit,ch->max_hit,ch);
*/
void bar_draw(int A, int B, CHAR_DATA * ch)
{
int percent;
int C;
percent = (A*100)/B;
send_to_pager("[", ch);
for (C = 0; C < 10; C++){
if( percent >= (C*10) ) send_to_pager(">", ch);
else send_to_pager("-", ch);
}
send_to_pager("]", ch);
return;
}
//--------------------------
| | 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.
77,779 views.
This is page 2, subject is 2 pages long:
1
2
It is now over 60 days since the last post. This thread is closed.
Refresh page
top