How to get the input.

Related but not the same as the other thread I was commenting in:

[code]To get an input:
(-VM_ReadKeyboard(buffer, parse):wink:

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?

Extra detail. If you type a correct response the first time, it works, but all following times, it is blank.

Am I supposed to do something to make it read the player’s command properly the second time through?

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."

Because the built in one explodes violently when combined with inline hyperlinks.

The one I cooked up works great… except for that strange hitch.

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 (::slight_smile: {
#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.

Test me with “l / l / l / yes”.

The Testing Room is A Room.[/code]

Hope this helps.

That looks like genius. Trying it.

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.

All fixed. Thanks guys.

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?

The Questions extension is designed for stuff like this.

Interesting, but would not work well to actually interrupt other processes, since it just uses the normal parser.

How can I get VM_ReadKeyboard to behave properly?

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.

Giving it a shot!

How do I set an inform 7 variable from within inform 6 code? I try and it says I’m referring a constant. Is it possible?

It sure is! You have to put the inform 7 variable inside “(+ +)” tags.

See “25.18. Longer extracts of Inform 6 code” in the Inform 7 documentation.

Hope this helps.

Ok, I’m getting awful close now. How do I get parse(which is an array?) into a single variable nice and neat? I want all of the words.

To get an input: (- for (::) { PrintText( "Hi!" ); #Ifdef TARGET_ZCODE; if (location == nothing || parent(player) == nothing) read buffer parse; else read buffer parse DrawStatusLine; #Ifnot; ! TARGET_GLULX; KeyboardPrimitive(buffer, parse); #Endif; ! TARGET_ (+ playerinput +) =parse-->1; PrintText( parse-->0); PrintText(" - "); PrintText( buffer-->1); PrintText( "Bye!" ); break; } -)

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?

Apologies for bumping, but does anyone know enough inform6 to take a crack at this?

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]

This produces output like the following:

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.