Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Can I limit the length of a textbox?

I have a "textbox" that allows the player to enter their name. (textbox is a sugarcube thing, i think? not sure)
However, there's nothing stopping them from having a character named "SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS"
And that's an issue. How could I limit the length of the textbox itself, or find a way to shorten the string afterwards if it exceeds a limit?
I'm using Twine 2.0.8 (.10 doesn't work?? Unrelated) with the Sugarcube format
Thanks :P

BONUS: Is it possible to make the "textbox" fit the size of my surrounding font? It's awfully small.


  • You need to state which Story Format you are using when you as a question because answers can be different for each one.
    You mention SugarCube but it is unclear if you are actually using it and if so which version (1 or 2)
  • greyelf wrote: »
    You need to state which Story Format you are using when you as a question because answers can be different for each one.
    Thanks pal, I edited it

  • Since you failed to specify which version of SugarCube you're using, I'm going to assume v1.

    You may change the visible length of the text input element created by <<textbox>> by changing its default style. For example: (goes in Story Stylesheet)
    input[type="text"] {
    	min-width: 12em; /* default: 20em */

    That doesn't change how long of a string they may enter, however. So, in addition to the above, you will likely also want to place something like the following somewhere within the passage where you're invoking <<textbox>>:
    postdisplay["textboxMaxlength"] = function (taskName) {
    	/* Limit textbox input elements to 12 characters. */
    	$(".macro-textbox").attr("maxlength", 12);
    	/* Make this a single-use task.*/
    	delete postdisplay[taskName];
    That will alter all of the text input elements created by <<textbox>> within the passage. If you only wish to alter some of them or have many passages containing <<textbox>> macros, then the setup will need to be a little different.

    Regarding the font. You may change the size, family, or both—though, I suggest only altering one at a time, until you find something you like. For example, to make the default font larger: (goes in Story Stylesheet)
    input[type="text"] {
    	font-size: 14px; /* default: 12px */
    Or, to change the default font (monospace) so that it matches the default font stack in SugarCube v1: (goes in Story Stylesheet)
    input[type="text"] {
    	font-family: Verdana, "DejaVu Sans", Helmet, Freesans, sans-serif; /* default: monospace */
Sign In or Register to comment.