Morrowind Mod:XTextInput

The UESPWiki – Your source for The Elder Scrolls since 1995
Jump to: navigation, search

A function added by MWSE.

xTextInput allows you to directly read keyboard input from the user and the results will be returned as a string. Pass a string and a virtual key code to the function. The function will wait for a key to be pressed and then take one of three actions. If the key pressed matches the endcode parameter, the string and its length are returned. If the key pressed is a printable ASCII character, the character is added to the string and the string and the number 0 are returned. If the key is RETURN or BACKSPACE, a new line is started or one character is removed from the string, and the modifed string and a 0 are returned. The function returns after each key press so that the current value of the string can be shown with xMessageFix and MessageBox but the string should only be used normally after the length is returned. Player controls should be disabled while this function is used.

Syntax[edit]

length (long), text (string): ref->xTextInput message (string), endcode (long)

Example[edit]

long endchar
long message
long length

ifx ( endchar )
else ; Initialization needed when endchar == 0
    DisablePlayerControls
    set endchar to 13 ; RETURN key
    setx message to xStringBuild "" ; Empty string to start
    set length to 0
    return
endif

ifx ( length )
else ; Actual string edit while length == 0
    setx length message to xTextInput message endchar
    ; Three boxes, makes it appear as if there is one set that changes.
    MessageBox ""
    ; Spaces and trailing % hide old characters while using Backspace.
    xMessageFix "%s %" message
    MessageBox " "
    MessageBox "Enter a message and press ENTER when it is complete."
    return
endif

EnablePlayerControls ; The message is complete now

See Also[edit]

xKeyPressed
xTextInputAlt