Jump to content

Home

Text Input Box?


Recommended Posts

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

[color=PaleGreen]// 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.
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [/color]
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"));
}


[color=PaleGreen]// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// 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.
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [/color]
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);
       }
   }
}


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


[color=PaleGreen]// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// ST: Use this in the callback script to get the string the player has "typed"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [/color]
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:

[color=PaleGreen]// ST: st_dlg_keyboard.nss  - Dialog action script[/color]
#include "st_inc_keyboard"


void main() {
   string sInput = GetScriptStringParameter(); [color=PaleGreen]// String Param field value[/color]

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

 

 

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

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

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

   [color=PaleGreen]// ST: The player has typed input, check if it matches the password, and print
   //     the result to the Feedback log.[/color]
   if (isCallback == 1) {
       string sPassword = ST_GetKeyboardInput();
       if (sPassword == "jedi") {
           SendMessageToPC(GetPartyLeader(), "You entered the correct password!"); 
       }
       else {
           SendMessageToPC(GetPartyLeader(), "Incorrect password entered!");       
       }
   }   
   [color=PaleGreen]// ST: The script is first run, ask for input.[/color]
   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.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...