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
➜ Character Creation
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Metsuro
USA (389 posts) Bio
|
Date
| Fri 09 Jun 2006 12:29 AM (UTC) |
Message
| I added this to character creation.
case CON_GET_LAST_NAME:
if( argument[0] == '\0' )
{
STRFREE( ch->lname );
sprintf( buf, "none");
ch->lname = STRALLOC( buf );
write_to_buffer( d, echo_on_str, 0 );
write_to_buffer( d, "\r\nWhat is your sex (M/F/N)? ", 0 );
d->connected = CON_GET_NEW_SEX;
break;
}
else
{
STRFREE( ch->lname );
sprintf( buf, "%s", argument);
ch->lname = STRALLOC( buf );
write_to_buffer( d, echo_on_str, 0 );
write_to_buffer( d, "\r\nIs this last name you wish? YES/NO", 0);
d->connected = CON_CONFIRM_LAST_NAME;
break;
}
case CON_CONFIRM_LAST_NAME:
switch ( argument[0] )
{
case 'y':
case 'Y':
write_to_buffer( d, echo_on_str, 0 );
write_to_buffer( d, "\r\nWhat is your sex (M/F/N)? ", 0 );
d->connected = CON_GET_NEW_SEX;
break;
case 'n':
case 'N':
write_to_buffer( d, echo_on_str, 0 );
write_to_buffer( d, "\r\nWhat is the last name you wish to have? [PRESS ENTER FOR NONE]", 0 );
d->connected = CON_GET_LAST_NAME;
break;
default:
write_to_buffer( d, "If thats not your last name, then what is?\r\n ", 0 );
return;
}
it works for the most part unless you input a name and go to is this the last name you wish to have? and if you hit n, it skips straight to class skipping both the both the place to reenter a last name, and where it puts in your sex, sets you has neutral then puts you right at the class selection |
Everything turns around in the end | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #1 on Fri 09 Jun 2006 01:12 AM (UTC) |
Message
| What is the expected behavior? It's hard to analyze the problem unless we know what it's supposed to do, and what it's doing instead. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Metsuro
USA (389 posts) Bio
|
Date
| Reply #2 on Fri 09 Jun 2006 01:20 AM (UTC) Amended on Fri 09 Jun 2006 01:21 AM (UTC) by Metsuro
|
Message
| If you input a name you get this message... Is this last name you wish? YES/NO. If you type yes it goes on the selection your sex, however if you select no, it should send you back to the begining to start over last name portion but it doesn't. It keeps the last name you put in, sets you to neutral sex and skips you down to class selection. Which to me it means that the it takes no from it skips something in the last name portion, and also takes the no as no for sex selection to set you as neutral then moves to class.
This is the output from the mud when you try do say no.
What is the last name you wish to have? [PRESS ENTER FOR NONE]Winne
Is this last name you wish? YES/NOn
What is the last name you wish to have? [PRESS ENTER FOR NONE]
Select a class, or type help [class] to learn more about that class.
[Mage Cleric Thief Warrior Vampire Druid Ranger Augurer Paladin]
:
|
Everything turns around in the end | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #3 on Fri 09 Jun 2006 01:28 AM (UTC) |
Message
| Here's the problem. With those 'breaks' in your code, you're breaking out of the inner switch, not the outer switch. To fix this, you need a 'break' at the end of the switch statement inside CON_CONFIRM_LAST_NAME. Not breaking out of a case statement is a common error; it's sometimes tricky but should be the first thing to look for. :)
I'm willing to bet that the case right after CON_CONFIRM_LAST_NAME is the one that picks character gender, which would explain why 'n' is setting gender to neutral. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Metsuro
USA (389 posts) Bio
|
Date
| Reply #4 on Fri 09 Jun 2006 02:34 AM (UTC) |
Message
| Oh well that seemed simple enough, I took the idea from the dbsc source and had to play with it and ended up just creating it from nothing. I guess I'll remember that switchs need breaks, not just some of them =P |
Everything turns around in the end | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #5 on Fri 09 Jun 2006 02:49 AM (UTC) |
Message
| The way it works is that 'break' leaves the switch statement. If you don't break, the code keeps going until it hits a 'break' or the end of the switch block.
That is why it works to have code like:
Basically what this is doing is that the case for 'y' runs the code, under it, and then since there is no break it overflows into the 'Y' code. In fact, it is possible to do something like:
case 'y':
printf("foobar");
case 'Y':
...
In this code, 'y' is the same thing as 'Y' except that it prints 'foobar' before doing whatever is in 'Y'. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | 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.
18,384 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top