Character Creation

Posted by Metsuro on Fri 09 Jun 2006 12:29 AM — 6 posts, 22,020 views.

USA #0
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
USA #1
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.
USA #2
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]
: 
Amended on Fri 09 Jun 2006 01:21 AM by Metsuro
USA #3
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.
USA #4
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
USA #5
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:
case 'y':
case 'Y':


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'.