Text Input With Pluggy
From The Elder Scrolls Construction Set Wiki
This is an update of the script given in Text Input With TSFC, using Pluggy string functions. By using Pluggy for the input, you now have the option to easily retain or save data for later use.
This code will accept text input from the player, storing the data in a Pluggy string. All regular keyboard characters are supported except tilde(~). Shift and Backspace may be used normally. Text is shown as typed via MessageBoxes, which also have buttons for the player to end their input or clear all input.
Contents |
[edit] Requirements
[edit] Setup
If you haven't set up DXtoToken, set it up now following the instructions in that article. This script uses the names recommended in that article for the activator.
As presented, this script is intended to run as a quest script and will use the player's input to rename an item. It could however be modified to use the input in a different way, or to run in an object's script.
After creating a quest for the script to run on, find the line "StopQuest TextInput" and replace "TextInput" with the name of your quest.
You'll then need to use the following snippet of code in another script when you're ready to get the player's input, assuming that you used the quest name TextInput.
set TextInput.item to myItem ; Must tell the script which item to rename StartQuest TextInput
[edit] Limitations
- It is impossible to support the tilde(~) or accent(`) keys.
- Caps Lock is ignored, since most players will use it to toggle run. It would be possible to add support for it, but it's not recommended.
- While the script can respond quickly, allowing the player to type at a fairly normal pace, if multiple keys are pressed at the same time only one of them will be recognized.
- If the typed text overflows to multiple lines on the MessageBox, a dash(-) will be shown at the end of each line (per normal grammar rules). This is a function of the game engine, and the actual text is not modified.
[edit] Functions & Scripting Concepts Used
- Activate
- CreateString
- DestroyString
- fQuestDelayTime
- GetButtonPressed
- GetKeyPress
- GetNumKeysPressed
- isKeyPressed2
- MenuMode
- SetString
- StopQuest
- StringCat
- StringLen
- StringMsgBox
- StringSetName
[edit] The Code
scn TextInputScript
ref item
float fQuestDelayTime
short control
short button
short console
long key
long shift
long name
long prompt
long clear
long done
long temp
begin menumode 1001
if ((isKeyPressed2 key) && (key != 42) && (key != 54))
return
else
set key to GetKeyPress 0
if (GetNumKeysPressed > 1)
set shift to GetKeyPress 1
if ((key == 42) || (key == 54))
set key to shift
set shift to 1
elseif ((shift == 42) || (shift == 54))
set shift to 1
else
set shift to 0
endif
else
set shift to 0
endif
endif
if ((key == 1) || (key == 42) || (key == 54) || (key > 57))
elseif (key == 41) ; Open/close console
if (console)
set console to 0
else
set console to 1
endif
elseif (console)
elseif (key == 14) ; Backspace
if (StringLen name)
set temp to (StringLen name) - 1
StringLen name temp
endif
SetString prompt "Name: "
StringCat prompt name
StringMsgBox prompt clear done
elseif (key)
set DXtoToken.dxKey to key
set DXtoToken.shift to shift
DXtoToken.activate player 1
set temp to DXtoToken.sToken
StringCat name temp
SetString prompt "Name: "
StringCat prompt name
StringMsgBox prompt clear done
endif
end
begin gamemode
set fquestdelaytime to 0.01
if (control)
set button to getbuttonpressed
if (button == 0)
StringLen name 0
SetString prompt "Name:"
StringMsgBox prompt clear done
elseif (button == 1)
StringSetName item name
DestroyString name
DestroyString prompt
DestroyString clear
DestroyString done
set control to 0
stopquest TextInput
endif
elseif (control == 0)
set name to CreateString -1 0 1
StringLen name 0
set prompt to CreateString -1 "Name:" 1
set clear to CreateString -1 "Clear All" 1
set done to CreateString -1 "Finish Input" 1
StringMsgBox prompt clear done
set control to 1
endif
end
[edit] See Also
- Text Input With OBSE - an alternative that does not require Pluggy.
- Text Input With TSFC - an alternative which uses TSFC.

