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;
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!
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.
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.
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!