Related but not the same as the other thread I was commenting in:
[code]To get an input:
(-VM_ReadKeyboard(buffer, parse)
To decide whether player consents:
say “[link]yes[end link] or [link]no[end link]>[line break][run paragraph on]”;
While 1 is 1:
get an input;
say “Your command is: [player’s command].”;
if the player’s command in lower case matches the text “yes”:
decide on true;
if the player’s command in lower case matches the text “no”:
decide on false;
if the player’s command in lower case matches the text “y”:
decide on true;
if the player’s command in lower case matches the text “n”:
decide on false;
say “[link]yes[end link] or [link]no[end link]>[line break][run paragraph on]”;
[/code]
There’s my code. The links work great, but if I just -type- yes or no, it doesn’t work. Player’s Command appears to be blank. Where is that hiding?
Is there a reason that you are reinventing the wheel here, rather than just using the built-in player consents phrase? If you want to bundle the links into “if the player…” phrase, this would be a better way to do it:
To decide whether the player assents:
say "[link]YES[end link] or [link]NO[end link]>>[line break][run paragraph on]";
if the player consents, decide yes;
decide no.
You would invoke this phrase in the same way as “if the player consents”:
Instead of jumping:
say "Are you sure?";
if the player assents:
say "Whee!";
otherwise:
say "You maintain your dignity."
It seems to work fine when I try it. Also, there is already an “if the player consents” phrase built in, so you don’t need to redefine it. If you just want to change the messages, you could try this.
[code]“Test”
Include Inline Hyperlinks by Erik Temple.
Include (-
[ YesOrNo i j;
for (: { #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;
if (i == YES1__WD or YES2__WD or YES3__WD) rtrue;
if (i == NO1__WD or NO2__WD or NO3__WD) rfalse;
}
PrintText((+ yes or no message +));
}
];
-) instead of “Yes/No Questions” in “Parser.i6t”.
The yes or no message is a text that varies. The yes or no message is “[link]yes[end link] or [link]no[end link]> [run paragraph on]”.
Every turn:
say “[link]yes[end link] or [link]no[end link]> [run paragraph on]”;
if the player consents begin;
say “Your command is: [player’s command].”;
say “Yes!”;
otherwise;
say “Your command is: [player’s command].”;
say “No!”;
end if.
We figured out the fix for the “explosion” in the other thread. Just add a run paragraph on or an explicit line break so that Inform doesn’t think it has to print an (illegal) line break between rules. You don’t need to reinvent the wheel.
If you want to replace the message for failed yes/no input, it would probably be better to use Default Messages by Ron Newcomb, rather than hack the Yes/No routine. But the latter works, as climbingstars shows.
Oops, there’s another place where I’m trying to get input in a loop, with the same bug.
To get an input:
(-VM_ReadKeyboard(buffer, parse);-)
while 1 is 1:
say "Type the name of the feat you want> [run paragraph on]";
get an input;
let q be the player's command;
say "Q is [q].";
It seems to get an input is extremely unreliable. Is there a better way to do that?
What do you mean by “interrupt other processes”? Questions hijacks the main input to put toward whatever purpose you like, and it uses the parser to allow you to restrict valid input to a certain class of entities. You can build your own input routine and parser if you like, but … why, when that’s (probably) not necessary?
If you really want to do this yourself, VM_ReadKeyboard is not the right point of entry. Take a look at the YesOrNo() routine in the I6 template (basically, the same routine that climbingstars included, with modification, in his/her post in this thread). Or you could use Glulx Input Loops to set up a line input loop with its own specific handling rules.
It captures nothing, parse–>0 returns nothing in printtext, as does buffer–>1, I’ve tried parse–>1. Where did the data go? How do I grab it and stuff it into playerinput?
You haven’t really explained what effect you’re trying to achieve, but here’s how to capture what I think you’re looking for using the Questions extension. (Sorry, I doubt you’re going to get any takers for helping you to reimplement the parser in I6. But I’ve been wrong before…)
[code]Include Questions by Michael Callaghan.
Bragging is an action applying to nothing. Understand “brag” as bragging.
Bombast Chamber is a room. “Here you may BRAG.”
Instead of bragging:
now current question is “”;
now current prompt is “Of what great feat do you wish to tell?[line break]>>”;
ask a closed question, in text mode;
Rule for printing a parser error when we are asking a question and the command parser error is the I beg your pardon error:
say “You decide not to speak.”;
deactivate text question mode.
A text question rule when the player is in the Bombast Chamber:
if the current answer matches the regular expression “^(I |My )”, case insensitively:
say “Plaudits resound!”;
exit;
otherwise:
say “Your story lacks verve. Try again.”[/code]
All I need to do it get input, and put it in a variable. I have the variable. I have input(I think). I just need to connect A to B. I can do all the parsing on my own, that is not the challenge. I just need one line of input. That’s it.