Using Twine 2, Sugarcube 2.
I have a text input, where the player can type something and stuff will happen depending on what they typed.
My problem: The way I have it set up, they have to press a "submit" button to get results.
Is there a way to make it so they just have to press enter?
Thanks!
Comments
If <<textbox>> isn't an option, then you're going to need to specify some details. Specifically, what kind of text input are you using and what does the "submit" button do?
<<textbox "$action" "" autofocus>><<button "submit">>
<<if $action neq "">>
<<if $action.split(" ").contains("kittens")>>
<<replace "#ActionText">><<print "There are kittens">><</replace>>
<<elseif $action eq "laugh">><<replace "#ActionText">><<print "AHAHAHAHAHAHA">><</replace>>
<<elseif $action eq "cry">><<replace "#ActionText">><<print "WAAAAAHHHHHHHHH">><</replace>>
<<else>><<replace "#ActionText">><<print "Nothing happens.">><</replace>>
<</if>>
<</if>>
<<if $action eq "">><<replace "#ActionText">><<print "Type in the action you'd like to take">><</replace>><</if>>
<</button>>
My issue is that in order to process whatever the player types in the text box, they have to click the submit button -- can I make it so they just have to press enter/return, instead of having to click a button?
http://twinery.org/forum/discussion/6432/running-script-on-keypress-in-a-textarea-sugarcube-2#latest
To validate within the same passage, via either <<click>> or <<button>>, you will instead need to hook enter/return keypresses within the <<textbox>> so that they trigger a click on your <<button>>.
Also, you are doing several unnecessary things within your <<button>> code.
Here's what I'd suggest for your <<textbox>> and <<button>>: And the following to enable the functionality you want: (goes in Story JavaScript)