Note: LucasForums Archive Project
The content here was reconstructed by scraping the Wayback Machine in an effort to restore some of what was lost when LF went down. The LucasForums Archive Project claims no ownership over the content or assets that were archived on archive.org.

This project is meant for research purposes only.

Text Input Box?

Page: 1 of 1
 glovemaster
06-08-2007, 2:47 AM
#1
I was just wondering, i haven't got KotOR at the moment so i can't check, but couldn't the input box used on the New Character screen, that you type your name into, be used from a script?

Thanks ;)
 stoffe
06-08-2007, 6:49 AM
#2
I was just wondering, i haven't got KotOR at the moment so i can't check, but couldn't the input box used on the New Character screen, that you type your name into, be used from a script?


No, there is currently no scripting function for accepting input from the user. The best you could do, as far as I am aware, is a "fake keyboard" dialog, where you have one reply for each letter in the alphabet and a script that concatenates the character the player chooses onto a Global string variable. The dialog would then loop up to the beginning to allow the player to pick another character, until they pick the "Done" node to submit the finished string, which the script that need the input then could read from the global string var.

Not exactly a quick and easy way to type, but it's the only way I can think of with what the scripting language provides. :)

(If it's for TSL you only need one include file to use it from other scripts, and one dialog script to control it all since you can set the typed letter via script parameters and run the "done, submit!" part of the script the same way. You can make the whole thing into a generic, re-usable function too. If it's for KOTOR you'll need one script for each letter to type and one to submit the string.)

I've been doing a quick test with this earlier. Here are the scripts I made for it, if you want them (hopefully I found the latest versions, my modding folder is a mess :)):

st_inc_keyboard.nss: Include file with general functions

// ST: Include file: st_inc_keyboard.nss

// NOTE: This include file needs the following Globals added to globalcat.2da:
// ST_KeyboardText (string)
// ST_KeyboardCallback (string)
// ST_KeyBoardCallbackTag (string)
// ST_KeyboardParam (number)

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// ST: Function used to run the Keyboard terminal dialog.
// sText = Text to display in the terminal to describe what the user should type
// sCallback = name of a script file to run when the user has finished "typing"
// iParam = Numeric parameter to send to the callback script, if needed.
// sCallbackTag = Tag of object that should run the callback script, leave blank
// to make the dialog owner (usually the player) run it.
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void ST_RunKeyboard(string sText, string sCallback, int iParam, string sCallbackTag = "") {
SetCustomToken(2100, sText);
SetCustomToken(2101, "");
SetGlobalString("ST_KeyboardText", "");
SetGlobalString("ST_KeyboardCallback", sCallback);
SetGlobalString("ST_KeyBoardCallbackTag", sCallbackTag);
SetGlobalNumber("ST_KeyboardParam", iParam);

AssignCommand(GetFirstPC(), ClearAllActions());
SetLockOrientationInDialog(GetFirstPC(), TRUE);
AssignCommand(GetFirstPC(), SetKeepStealthInDialog(TRUE));
AssignCommand(GetFirstPC(), ActionStartConversation(GetFirstPC(), "st_keyboard"));
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// ST: Run this function when the user is done "typing" and picks the "I'm done" reply.
// If anything has been typed the callback script will be run.
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void ST_SubmitKeyboardInput() {
if (GetStringLength(GetGlobalString("ST_KeyboardText")) > 0) {
string sCallback = GetGlobalString("ST_KeyboardCallback");
string sOwner = GetGlobalString("ST_KeyBoardCallbackTag");
int iParam = GetGlobalNumber("ST_KeyboardParam");

object oOwner = OBJECT_SELF;
if (sOwner != "") {
oOwner = GetObjectByTag(sOwner);
}

if (GetIsObjectValid(oOwner) && (sCallback != "")) {
ExecuteScript(sCallback, oOwner, iParam);
SetGlobalString("ST_KeyboardCallback", "");
SetGlobalString("ST_KeyBoardCallbackTag", "");
SetGlobalNumber("ST_KeyboardParam", 0);
}
}
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// ST: Run this when the player picks a character reply node in the keyboard dialog.
// This will add the selected character to the string.
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void ST_AddCharacter(string sChar) {
string sText = GetGlobalString("ST_KeyboardText");
sText += sChar;
SetGlobalString("ST_KeyboardText", sText);
SetCustomToken(2101, sText);
}


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// ST: Use this in the callback script to get the string the player has "typed"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string ST_GetKeyboardInput() {
return GetGlobalString("ST_KeyboardText");
}


st_dlg_keyboard.nss: Dialog Action script - used on all the Reply nodes in the "Keyboard" dialog. for the letter/character replies, set String Param to the letter typed, and leave String Param blank on the Submit/I'm done node:

// ST: st_dlg_keyboard.nss - Dialog action script
#include "st_inc_keyboard"


void main() {
string sInput = GetScriptStringParameter(); // String Param field value

// ST: A character has been set, add it to the string
if (GetStringLength(sInput) == 1) {
ST_AddCharacter(sInput);
}
// ST: No character set, submit the whole string
else {
ST_SubmitKeyboardInput();
}
}



st_keyboardtest.nss: Test script that runs the keyboard and then reacts to the user input:

// ST: st_keyboardtest.nss
// Ask for a password and write to the feedback log if the proper one was specified.
#include "st_inc_keyboard"

void main() {
int isCallback = GetRunScriptVar();

// ST: The player has typed input, check if it matches the password, and print
// the result to the Feedback log.
if (isCallback == 1) {
string sPassword = ST_GetKeyboardInput();
if (sPassword == "jedi") {
SendMessageToPC(GetPartyLeader(), "You entered the correct password!");
}
else {
SendMessageToPC(GetPartyLeader(), "Incorrect password entered!");
}
}
// ST: The script is first run, ask for input.
else {
string sTerm = "Please enter the password to proceed:";
ST_RunKeyboard(sTerm, "st_keyboardtest", 1);
}
}


The Entry node in st_keyboard.dlg where the player replies are listed under should then have the following set as text...

<CUSTOM2100>
Input: <CUSTOM2101>

...which would make it show the text of the terminal ("Please enter the password to proceed") followed by what the player has "typed" so far.
 glovemaster
06-08-2007, 10:23 AM
#3
Well, your way seems the only possible way. Quite ingenious if I may say so, in addition to being quite heavy :p I've had a look now and i can't see anything that will give an input box. Thanks then ;)
Page: 1 of 1