If you do it like this instead you don't need the goto statements, and you can remove the state CON_CLASS_CHECK case CON_QRACE: int_arg = atoi (arg); // This converts the string to an integer value. load_result = parse_race(int_arg); if (load_result == RACE_UNDEFINED) { SEND_TO_Q("\nThat is an Invalid Race ... *sigh*\n", d); return; } else { GET_RACE(d->character) = load_result; } /* Here you roll the abilities */ do_start_I(d->character); /* And print the result of the rolls */ /* Then show what classes are availabe */ parse_class_II(d->character); /* Ask the player if he want to keep the stats etc. */ SEND_TO_Q("Please type [Y]es to re-roll, [R]ace to select another race,\n" "[Q]uit to Wimp out or any other key to *accept* these rolls and\n" "continue... [Y/R/Q]:-", d); /* Now set STATE */ STATE(d) = CON_ROLLS; break; CASE CON_ROLLS: switch (*arg) { case 'y': case 'Y': /* Reroll the abilities */ do_start_I(d->character); /* Show the abilities and available classes */ parse_class_II(d->character); /* Ask the player if he want to keep the stats etc. */ SEND_TO_Q("Please type [Y]es to re-roll, [R]ace to select another race,\n" "[Q]uit to Wimp out or any other key to *accept* these rolls and\n" "continue... [Y/R/Q]:-", d) break; case 'r': case 'R': SEND_TO_Q(race_menu, d); SEND_TO_Q("\nWhich Race do you wish to select ? :", d); STATE(d) = CON_QRACE; break; case 'Q': case 'q': SEND_TO_Q("\nFair Enough .... WIMP! Have fun in reality ...\n\n", d); STATE(d) = CON_CLOSE; break; default: SEND_TO_Q(class_menu, d); SEND_TO_Q("Please select a class :-", d); STATE(d) = CON_QCLASS; break; } break; -Johan > From: "DJ Pure" <pure@ozramp.net.au> > > G'Day all. > I wanted to add a re-roll function in the Nanny() function. > I added it fine (after hours of trying to figure out STATE and all this > other stuff, but I REALLY REALLY don't like MY OWN CODE. > > ** I had to use two *GOTO* statements, and i don't want to (bad programming > practice ... **** > > Any helps would be appreciated. > > Jussy. > > NOTE : The code DOES run fine. > NOTE 2 : I sorta cannot understand the STATE thingy. As far as I know / > understand, it checks the roots of the program for the current state it's > in (like a Finite State machine or something). And if it's not connected it > goes back to the last state until it gets out of nanny (ie connected and > playing). But in that loop, it also waits for a user input, which is > something I DON'T want. > > anyways .. here's my code .. Good Luck! and thanks in advance for any > helpful idea's > > ----------8< snip snip >8--------------- > <in interpreter.c .. in the nanny function ..> > ... > case CON_QRACE: > int_arg = atoi (arg); // This converts the string to an integer value. > load_result = parse_race(int_arg); > if (load_result == RACE_UNDEFINED) > { > SEND_TO_Q("\nThat is an Invalid Race ... *sigh*\n", d); > SEND_TO_Q("Ok .. Now lets try that again ...\n",d); > return; > } > else { > GET_RACE(d->character) = load_result; > } > > // Now lets roll the players abilities. > // Jus - 12/10/96 > goto forced_to_do_con_rolls; > //STATE(d) = CON_ROLLS; > // If i use the STATE .. then i waits for the player to give some input, > which i > // don't want ... > break; > > > case CON_ROLLS : > forced_to_do_con_rolls: // Unwanted Label added here .. out of necessity > =(. > > // This is case statement for controlling the players ability to choose > // their characters ability rolls. > // Jus - 12/10/96 > > //Ok. Lets create a new character. > if (!GET_LEVEL(d->character)){ > do_start_I(d->character); // Rolls the die > } > > sprintf (buf, "\nCharacter's Rolls -: \n"); > // <blahblahblahblah .. lots of sprintf's with ability rolls> > send_to_char(buf, d->character); > > // Test for valid classes. > // This function just determins what classes are available to the player, > dependant > // upon RACE and ROLLS (they are displayed to the screen) > parse_class_II(d->character); > > SEND_TO_Q("Please type [Y]es to re-roll, [R]ace to select another race,\n" > "[Q]uit to Wimp out or any other key to *accept* these rolls and\n" > "continue... [Y/R/Q]:-", d); > STATE(d) = CON_CLASS_CHECK; > break; > > > // This Checks to see if the user wants to continue or not. > case CON_CLASS_CHECK: > switch (*arg) { > case 'Y' : case 'YE' : case 'YES' : case 'y' : case 'ye' : > case 'yes' : case 'Yes' : > send_to_char ("Ok. Re-rolling your character ...", d->character); > d->character->player.level = 0; > goto forced_to_do_con_rolls; > // I DON'T WANT THAT GOTO ADDED HERE ALSO, but i need it .. =( > break; > > case 'Q' : case 'q' : case 'quit' : case 'Quit' : > send_to_char ("\nFair Enough .... WIMP! Have fun in reality ...\n\n", > d->character); > close_socket(d); break; > > case 'R' : case 'r' : case 'race' : case 'Race' : > SEND_TO_Q(race_menu, d); > SEND_TO_Q("\nWhich Race do you wish to select ? :", d); > STATE(d) = CON_QRACE; > break; > > default : > SEND_TO_Q(class_menu, d); > SEND_TO_Q("Please Select a Class :-", d); > STATE(d) = CON_QCLASS; > break; > } > break; > > > > case CON_QCLASS: > etc etc etc etc .. > > thanks and good luck. > > +-----------------------------------------------------------+ > | Ensure that you have read the CircleMUD Mailing List FAQ: | > | http://cspo.queensu.ca/~fletcher/Circle/list_faq.html | > +-----------------------------------------------------------+ > > +-----------------------------------------------------------+ | Ensure that you have read the CircleMUD Mailing List FAQ: | | http://cspo.queensu.ca/~fletcher/Circle/list_faq.html | +-----------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/18/00 PST