Original Parser

version 1 by Ron Newcomb

  • Home page
  • Beginning
  • Previous
  • Next

  • Chapter - Yes/No Questions

    [ see bug #752 ]
    To decide if the player consents (this is YesOrNo):
        repeat forever:
            draw the status line;
            read a command into the player's input buffer and parse it into the player's parsed command;
            if the number of words in the player's parsed command is at least one:
                let the word be the 1st word of the player's parsed command;
                if the word is 'YES', yes;
                if the word is 'NO', no;
            issue the 1st message for the quitting the game action; [ "Please answer yes or no." ]
            say "> ".

    [ YesOrNo i j;
    for (::) {
    KeyboardPrimitive(buffer, parse); ! see bug #752 on Mantis for why I did this.
    #Ifdef TARGET_ZCODE;
    !if (location == nothing || parent(player) == nothing) read buffer parse;
    !else read buffer parse DrawStatusLine;
    j = parse->1;
    #Ifnot; ! TARGET_GLULX;
    !KeyboardPrimitive(buffer, parse);
    j = parse-->0;
    #Endif; ! TARGET_
    if (j) { ! at least one word entered
    i = parse-->1; ! get first word
    if (i == YES1__WD or YES2__WD or YES3__WD) rtrue;
    if (i == NO1__WD or NO2__WD or NO3__WD) rfalse;
    L__M(##Quit, 1); print "> ";