29 Jan, 2010, Krysis wrote in the 1st comment:
Votes: 0
Hey all,

I can't for the life of me figure out how to collect input from the player (and eventually use this). I've been scanning over the various pieces of code bits to try and understand what exactly is going on when the player provides input during character creation (ie. Your Name:, Password: , etc.) as well as when an immortal is adding room descriptions (eg. Enter room description:)… but, I haven't figured out how to use the various functions to wait for input from the player, place that input in a buffer/char array, and use it.

I've taken a look at the following functions/structs (which essentially had me running in circles):

int process_input(struct descriptor_data *t); (which led me to)
int get_from_q(struct txt_q *queue, char *dest, int *aliased); (which led to…)
struct txt_q (which led to…)
struct txt_block (which led to…)
void write_to_q(const char *txt, struct txt_q *queue, int aliased);

I also tried my hand at understanding how these file descriptors were being used:
FD_ZERO(&input_set); // Which I'm assuming clears the &input_set file descriptor, where input_set is
// of type fd_set.
FD_SET(d->descriptor, &input_set); // I didn't quite understand what this did.. but I figured I'd need it.


Anyway, all I'm really trying to do is ask the player a series of questions that require input (for example: where "->" denotes the player's input to the game)

"Do you want to start this random adventure: (Yes/No)"
-> Yes
"What adventure do you wish to begin? "
-> The super Cool adventure
"Alright, starting adventure: The Super Cool Adventure"

Anyway, let me post some of the structs/function code that I mentioned earlier so that you can have a deeper understanding of what they do.

int get_from_q(struct txt_q *queue, char *dest, int *aliased)
{
struct txt_block *tmp;

/* queue empty? */
if (!queue->head)
return 0;

tmp = queue->head;
strcpy(dest, queue->head->text);
*aliased = queue->head->aliased;
queue->head = queue->head->next;

free(tmp->text);
free(tmp);

return 1;
}

struct txt_block {
char *text;
int aliased;
struct txt_block *next;
};

struct txt_q {
struct txt_block *head;
struct txt_block *tail;
};

void write_to_q(const char *txt, struct txt_q *queue, int aliased)
{
struct txt_block *newt;

CREATE(newt, struct txt_block, 1);
CREATE(newt->text, char, strlen(txt) + 1);
strcpy(newt->text, txt);
newt->aliased = aliased;

/* queue empty? */
if (!queue->head) {
newt->next = NULL;
queue->head = queue->tail = newt;
} else {
queue->tail->next = newt;
queue->tail = newt;
newt->next = NULL;
}
}

#ifdef __CXREF__
#undef FD_ZERO
#undef FD_SET
#undef FD_ISSET
#undef FD_CLR
#define FD_ZERO(x)
#define FD_SET(x, y) 0
#define FD_ISSET(x, y) 0
#define FD_CLR(x, y)
#endif


The process_input() snippet is rather lengthy, and if you would like for me to post that as well… let me know! Or email me at: keno2500@yahoo.com or we can AIM or talk on MSN! I'll be happy to solve this FRUSTRATING problem! Thanks!
30 Jan, 2010, quixadhal wrote in the 2nd comment:
Votes: 0
The traditional way to do this in most Dikurivatives is to add states to the nanny function. So, rather than CON_PLAYING or similar, you'd set your state to be CON_DIALOG_1 and then add a case to process input received while in that state.

If you do this frequently, you will probably want to add a sub-state variable to your descriptor structure so you don't have to code everything in nanny itself. That way CON_DIALOG would just call process_dialog() and then use the sub-state to work out which part of which dialog you're in.

There are other ways to do it, but that's the one that'll be most similar to what's already there.
30 Jan, 2010, Krysis wrote in the 3rd comment:
Votes: 0
Ahhhh ha,

Thank you VERY much! I started to head down this direction and for some reason - abandoned it. This will help out a lot! Thanks again!
0.0/3