Couldn't I do something like....
switch( argument )
{
if (argument[0] == '\0' || UPPER(argument[0]) == 'N')
{
stc("Player not deleted.\n\r",ch);
}
if (UPPER(argument[0]) == 'Y' )
{
sprintf(buf,"%s deleted.", ep->d_name);
stc(buf,ch);
sprintf(buf,"%s/%s", PLAYER_DIR, ep->d_name);
unlink(buf);
sprintf(buf,"%s deleted.", ep->d_name);
stc(buf,ch);
}
}
Atm
----- Original Message -----
From: "Richard Lindsey" <[EMAIL PROTECTED]>
To: "Jeremy Hill" <[EMAIL PROTECTED]>; <[email protected]>
Sent: Tuesday, February 15, 2005 9:12 AM
Subject: RE: How do I... (yes or no input question)
Yeah I was about to suggest function pointers until I read lower in your
post, so I'll just enhance the idea of function pointers a bit :D you
could also have a sort of 'stage' variable associated w/ the function,
so that you could do something similar to the following, after adding
some kind of command lookup function (as opposed to the default code in
void interpret which just loops through the table):
void do_player( CHAR_DATA *ch, char *argument )
{
int cn = cmd_lookup("player");
switch( ch->cmd_stage )
{
case 0:
// initial output display w/ listing of players, and a prompt
to ask if you wish to delete so-and-so...
// upon success of the command, and verification that cn !=
-1, it'll do something like this:
ch->cmd_func = *cmd_table[cn].do_fun;
ch->cmd_stage++;
break;
case 1:
// Takes a yes or no argument as an answer to the question
asked in case 0...
// upon success of the command, and verification that cn !=
-1 (if any checks fail we'd reset their cmd_func to NULL and cmd_stage
to 0, perhaps even implement a question to verify that they absolutely
want to delete the character, and then:
// ch->cmd_func should already be equal to this do_fun, so we
don't need to reset it...
ch->cmd_stage++;
break;
case 2:
// Takes a yes or no argument as an answer to the
verification, performs the deletion of the pfile, echos a success
message (or failure), and resets cmd data:
ch->cmd_func = NULL;
ch->cmd_stage = 0;
break;
default: // Check for sanity
// Outputs some kind of error message that they're in an
unknown stage setting, perhaps does a loop through the cmd_table to find
a matching do_fun value in case some other function forgot to reset its
data, and we could log that to help hunt down any mistakes in other
functions, and then reset the data:
ch->cmd_func = NULL;
ch->cmd_stage = 0;
break;
}
return;
}
If you wanted, you could also make some sort of macro to set the command
data, like SET_CMD(ch) ((ch)->cmd_func = cn == -1 ? NULL :
*cmd_table[cn].do_fun; (ch)->cmd_stage++;) although that syntax may have
an error, it might need braces or something, and then you could just do
all of your validity checks in the case statement and do a SET_CMD(ch);
Anyhoo, that's just an expansion on Jeremy's idea :)
Richard Lindsey