lfnetwork.com mark read register faq members calendar

Thread: Text Input Box?
Thread Tools Display Modes
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Old 06-08-2007, 02:47 AM   #1
glovemaster
Now-a-days GroovyCarrot
 
Join Date: Jan 2007
Location: Liverpool, UK
Posts: 697
Current Game: No time for games, sadly
Helpful! 
Text Input Box?

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


If you're looking for any of the junk I did a few years ago; you can probably still find it all on filefront

Last edited by glovemaster; 01-21-2009 at 12:41 PM.
glovemaster is offline   you may: quote & reply,
Old 06-08-2007, 06:49 AM   #2
stoffe
Network Caretaker
 
stoffe's Avatar
 
Status: Administrator
Join Date: Apr 2002
Posts: 5,833
Helpful! 10 year veteran! Notable contributor 
Quote:
Originally Posted by glovemaster
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
Code:
// 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:
Code:
// 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:
Code:
// 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...
Code:
<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.

Last edited by stoffe; 06-08-2007 at 07:49 AM.
stoffe is offline   you may: quote & reply,
Old 06-08-2007, 10:23 AM   #3
glovemaster
Now-a-days GroovyCarrot
 
Join Date: Jan 2007
Location: Liverpool, UK
Posts: 697
Current Game: No time for games, sadly
Helpful! 
Well, your way seems the only possible way. Quite ingenious if I may say so, in addition to being quite heavy I've had a look now and i can't see anything that will give an input box. Thanks then


If you're looking for any of the junk I did a few years ago; you can probably still find it all on filefront

Last edited by glovemaster; 01-21-2009 at 12:41 PM.
glovemaster is offline   you may: quote & reply,
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Go Back   LucasForums > Network > Knights of the Old Republic > Editing / Modding > Holowan Laboratories > Text Input Box?

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:25 AM.

LFNetwork, LLC ©2002-2011 - All rights reserved.
Powered by vBulletin®
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.