Input.js (system script)
From Spheriki
The system script input.js provides a function that allows users to type in a string using the keyboard.
Contents |
Usage
RequireSystemScript("input.js");
Variables and functions of input.js
- GetString(x, y, font, max_chars)
- enables the user to type in a string and returns that string when done.
- the string is displayed at (x, y) using the Font object 'font'. The parameter 'max_chars' sets the maximal number of characters that may be entered. If it remains undefined it defaults to 256.
Example
RequireSystemScript("input.js");
font = GetSystemFont();
function Welcome() {
// Ask for name
font.drawText(0, 0, "Please enter your name:");
var name = GetString(0, font.getHeight(), font);
// Display welcome text
font.drawText(0, 0, "Pleased to meet you, "+name+"!");
FlipScreen();
// Wait until any key is pressed
GetKey();
}
Notes
- The current screen is grabbed and drawn as a background image during input.
- "|" is used as a cursor symbol.
- If the text exceeds the right border of the screen, there'll be no line feed.
See also
- RequireSystemScript()
- Sphere Font object
- GetSystemFont()
- Font.drawText()
- Font.getHeight()
- FlipScreen()
- GetKey()