Just replace the if from your original script from
if(sPlayerAnswer == “”)
to
if(sPlayerAnswer == " ")
Just replace the if from your original script from
if(sPlayerAnswer == “”)
to
if(sPlayerAnswer == " ")
Think I’ve already tried that, but ok, will try again. Tried it like this and NOTHING happens when I do it like this (to clarify: nothing happens when pressing “Okay” and not writing anything in the box), so if it works for you guys you must have done something completely different with your DisplayInputBox script:
//gui_checkanswer
#include "ginc_ipspeaker"
void main(string sPlayerAnswer)
{
if(sPlayerAnswer == " ")
{
SetCustomToken(1001, "Mike");
//SetLocalString(GetModule(), "CUSTOM24", sPlayerAnswer); //To be able to call this inside a script and just not just in a conversation by <CUSTOM1001>.
//According to 4760 (Thierry) one should use numbers above 1000 to be safe that it's not already used by the engine, but I read in NWNlexicon that number 24 wasn't used.
object oPC = GetPCSpeaker();
SetGlobalInt("playernamed",1);
AssignCommand(oPC, ClearAllActions());
CreateIPSpeaker("thenueh", "c_a_intro2", GetLocation(GetFirstPC()), 0.5f);
}
else
{
SetCustomToken(1001, sPlayerAnswer);
//SetLocalString(GetModule(), "CUSTOM24", sPlayerAnswer); //To be able to call this inside a script and just not just in a conversation by <CUSTOM1001>.
//According to 4760 (Thierry) one should use numbers above 1000 to be safe that it's not already used by the engine, but I read in NWNlexicon that number 24 wasn't used.
object oPC = GetPCSpeaker();
SetGlobalInt("playernamed",1);
AssignCommand(oPC, ClearAllActions());
SetCutsceneMode(oPC);
CreateIPSpeaker("thenueh", "c_a_intro2", GetLocation(GetFirstPC()), 0.5f);
}
}
When you say nothing happens you mean absolutely nothing or just the part in the if?
Does the part in the “else” run?
I have tested your script and added one simple line right after the first check
FloatingTextStringOnCreature(“Empty String”, GetFirstPC(), FALSE);
and it works.
Precisely. IF I just click “Okay” in the Display box absolutely nothing happens. It is as if it knows I have put in a blank space but refuses to run the script there, cause otherwise the logical thing would be to continue to the “else part”.
Urrgh. I think I’ll give up on this.
Looks like the script is not running at all then.
Just make sure the script is named correctly and that you didn’t mistype something by accident with a later edit in the callback parameters of the displaybox.
Now I tested this thoroughly. It works, I can confirm 100%.
Also, you’re not reloading a saved game, are you?
Nope
I’ll do one last test, and save the whole damn thing, relolad the toolset and try. For the moment I’m in Campaign mode and that’s pretty new to me. Maybe it has something to do with that, though that is highly inlikely since I change stuff in the script all the time and change it back to my original stuff and then it would be the same all the time, but things change when I change them and try them ingame.
You have in other words written my exact scripts into your toolset and it works 100% ?
Yes, for the small exception of the one line I typed after the first check to see if it was running at all, and it was.
The rest of the code I can’t tell if it runs or not because I dont have those convos so of course it does nothing for me. But that would be irrilevant to the if check.
I have a conversation, at next to last node in the first “node-tree” I run the displaybox_show script. And then everything runs, and if everyting works as should, it does that when you write something, and click “Okay” or you click “Cancel”, the next “node-tree” in the same conversation runs. Each “node-tree” is set to Once Per Game.
Tried it once more and it just doesn’t work. I give up on this. I still don’t think that you can call a string this way, since my brother told me this and he’s a prorgammer, and if everyone here hasn’t tried with a conversation and run my two scripts (or rather the DisplayInputBox script) from the conversation, like I do, I think that maybe it could have to do with that. Otherwise it ought to have worked on my part. It must have to do with something like that, or else it’s just another bug in NWN2. I have tripled checked my scripts and my conversation so…
Does that code work at all without the if checks? It could just be that there’s a wrong definition in the subject in there, but the problem that was raised in this thread was about the string check in the if call, and I’m sorry, but that one is tested to work 100%.
If the rest of the code does not work it’s because of something else, not the string check.
Again, without knowing your precise gui call script, it’s hard to give a response.
What does debug code say is being returned when left blank?
I recall that in my own examples, I also ensured the xml returned a default value (like that random stuff) when left blank, which means I also edited the XML callback being used. i.e. You may need to edit an XMl to do this sort of thing … dependant on more details.
Lance.
If I do it like this and everything works except for the click-on-the-okay-button-without-writing-an-answer. This is all the code I’m using. Don’t know what more code you want:
//displaybox_show
void main()
{
object oPC = GetPCSpeaker();
int nMessageStrRef = -1;
string sMessage = ("Your answer is:");
string sOkCB = "gui_checkanswer";
string sCancelCB = "gui_noanswer";
int bShowCancel = TRUE;
string sScreenName = "";
int nOkStrRef = 181744;
string sOkString = "";
int nCancelStrRef = 181745;
string sCancelString = "";
string sDefaultString = ""; //default text in the message box…
DisplayInputBox(oPC, nMessageStrRef, sMessage, sOkCB, sCancelCB, bShowCancel, sScreenName, nOkStrRef, sOkString, nCancelStrRef, sCancelString, sDefaultString);
}
//gui_checkanswer
#include "ginc_ipspeaker"
void main(string sPlayerAnswer)
{
SetCustomToken(1001, sPlayerAnswer);
//SetLocalString(GetModule(), "CUSTOM24", sPlayerAnswer); //To be able to call this inside a script and just not just in a conversation by <CUSTOM1001>.
//According to 4760 (Thierry) one should use numbers above 1000 to be safe that it's not already used by the engine, but I read in NWNlexicon that number 24 wasn't used.
object oPC = GetPCSpeaker();
SetGlobalInt("playernamed",1);
AssignCommand(oPC, ClearAllActions());
SetCutsceneMode(oPC);
CreateIPSpeaker("thenueh", "c_a_intro2", GetLocation(GetFirstPC()), 0.5f);
}
//gui_noanswer
#include "ginc_ipspeaker"
void main()
{
SetCustomToken(1001, "Mike");
//SetLocalString(GetModule(), "CUSTOM24", sPlayerAnswer); //To be able to call this inside a script and just not just in a conversation by <CUSTOM1001>.
//According to 4760 (Thierry) one should use numbers above 1000 to be safe that it's not already used by the engine, but I read in NWNlexicon that number 24 wasn't used.
object oPC = GetPCSpeaker();
SetGlobalInt("playernamed",1);
AssignCommand(oPC, ClearAllActions());
CreateIPSpeaker("thenueh", "c_a_intro2", GetLocation(GetFirstPC()), 0.5f);
}
And I’ve tried changing the gui_answer script with your suggestions here:
//gui_checkanswer
#include "ginc_ipspeaker"
void main(string sPlayerAnswer)
{
if(sPlayerAnswer == " ")
{
SetCustomToken(1001, "Mike");
//SetLocalString(GetModule(), "CUSTOM24", sPlayerAnswer); //To be able to call this inside a script and just not just in a conversation by <CUSTOM1001>.
//According to 4760 (Thierry) one should use numbers above 1000 to be safe that it's not already used by the engine, but I read in NWNlexicon that number 24 wasn't used.
object oPC = GetPCSpeaker();
SetGlobalInt("playernamed",1);
AssignCommand(oPC, ClearAllActions());
CreateIPSpeaker("thenueh", "c_a_intro2", GetLocation(GetFirstPC()), 0.5f);
}
else
{
SetCustomToken(1001, sPlayerAnswer);
//SetLocalString(GetModule(), "CUSTOM24", sPlayerAnswer); //To be able to call this inside a script and just not just in a conversation by <CUSTOM1001>.
//According to 4760 (Thierry) one should use numbers above 1000 to be safe that it's not already used by the engine, but I read in NWNlexicon that number 24 wasn't used.
object oPC = GetPCSpeaker();
SetGlobalInt("playernamed",1);
AssignCommand(oPC, ClearAllActions());
SetCutsceneMode(oPC);
CreateIPSpeaker("thenueh", "c_a_intro2", GetLocation(GetFirstPC()), 0.5f);
}
}
And with this the click-on-the-okay-button-without-writing-an-answer still doesn’t work.
If it’s a string problem or something else, I no longer know. I’m just tired of this whole debauckle. I thought it would be a simple thing to solve, but that never seems to be the case with NWN2. It’s not even that impportant, I guess. It just annoys the heck out of me when stuff like this works for everyone else except for me.
Hi,
OK … I recall DisplayInputBox causing me some issues and resorted to deploying my own text GUI input XML and functions, so it may be simply a function issue. (Or like you, I could not get it to play along as expected.) i.e. The gui_checkanswer as you use it does not send the kind of return you expect if the callback for the function even works! I just checked my own scripts and found I never ended up using it anywhere, so maybe there is a good reason I didn’t.
Now, I know this is now going well into more complex than you first requested, but here is my basic text input XML code in case you wanted to pursue your own text input box … NOTE: I pass STOPNAME when the player does not type anything … and I have this in my gui_textinput script. (Equivalent to your gui_checkanswer script.)
// FIX GUI CANCEL ENTRY
if(TextInput == "STOPNAME"){TextInput = "";}
TextInput.xml
<?xml version="1.0" encoding="NWN2UI">
<UIScene name="TextInputGUI" width=500 height=240 x=ALIGN_CENTER y=ALIGN_CENTER fadeout="0.2" fadein="0.2" backoutkey=false
scriptloadable=true priority="SCENE_SCRIPT" draggable=true idleexpiretime=0.1 OnAdd=UIScene_OnAdd_SetFocus(TextNameInput)/>
<!-- Title Pane -->
<UIPane name="TitlePane" x=ALIGN_CENTER y=10 width="PARENT_WIDTH" height="40" capturemouseclicks="false">
<UIText name="TitleText" text="Input Text Box" x=0 y=0 width="PARENT_WIDTH" height=30 align="center" valign="middle" fontfamily="Special_Font" style="4"/>
</UIPane>
<!-- TEXT INFORMATION - NAME -->
<UIText name="TextName" text="Type Response Below:" x=ALIGN_CENTER fontfamily="Body_Font" style=4 y=45 width=400 height=55 valign="middle" align="center"/>
<!-- TEXT INPUT BOX - SEE FRAME NEXT FOR ACTUAL BOX DRAWING -->
<UIText name="TextNameInput" valign="middle" align="left" x=ALIGN_CENTER fontfamily="Body_Font" style=4 y=116 width=400 height=18
multiline="false" returnrestricted="true" allowspace=true selectable=true editable=true maxlength=45
update=true OnUpdate=UIObject_Misc_SetLocalVarString(local:0) OnReturn=UIObject_Misc_ExecuteServerScript("gui_textinput",local:0) OnReturn0=UIButton_Input_ScreenClose()/>
<!-- DRAWS A BOX AROUND THE TEXT INPUT BOX -->
<UIFrame name="NameInputFrame" x=ALIGN_CENTER y=114 width=404 height=22 topleft="tp_frame_tl.tga" topright="tp_frame_tr.tga" bottomleft="tp_frame_bl.tga" bottomright="tp_frame_BR.tga" top="tp_frame_t.tga" bottom="tp_frame_b.tga"left="tp_frame_l.tga" right="tp_frame_r.tga" fillstyle="stretch" fill="tp_frame_bg.tga" border=5 />
</UIPane>
<!-- Ok Button -->
<UIButton name="OK" text="Ok" x=84 y=180 style="STYLE_SMALL_BUTTON"
OnToolTip='UIObject_Tooltip_DisplayTooltipString("Accepts the current input as a response.","OBJECT_X","OBJECT_Y","SCREEN_TOOLTIP_2")' OnLeftClick0=UIObject_Misc_ExecuteServerScript("gui_textinput",local:0) OnLeftClick1=UIButton_Input_ScreenClose() />
<!-- Cancel Button (Add other scripts if required.) -->
<UIButton name="Cancel" text="Cancel" x=292 y=180 style="STYLE_SMALL_BUTTON"
OnToolTip='UIObject_Tooltip_DisplayTooltipString("Ignores anything in the response box and exits interaction.","OBJECT_X","OBJECT_Y","SCREEN_TOOLTIP_2")'
OnLeftClick0=UIObject_Misc_ExecuteServerScript("gui_textinput","STOPNAME") OnLeftClick1=UIButton_Input_ScreenClose() />
<!-- Background Image -->
<UIFrame name="frmBackground" x=0 y=0 width=PARENT_WIDTH height=PARENT_HEIGHT topleft="tp_frame_tl.tga" topright="tp_frame_tr.tga" bottomleft="tp_frame_bl.tga"
bottomright="tp_frame_BR.tga" top="tp_frame_t.tga" bottom="tp_frame_b.tga" left="tp_frame_l.tga" right="tp_frame_r.tga" fillstyle="stretch" fill="tp_frame_bg.tga"border=10 />
And here is a function that uses it … Called from script that triggers the input GUI.
///////////////////////////////////////////////////////////////////////////////////////////////////
// Set Item Name via GUI input box.
///////////////////////////////////////////////////////////////////////////////////////////////////
void LBSetEnchantedItemName(object oPC, object oItem);
void LBSetEnchantedItemName(object oPC, object oItem)
{
// DISPLAY A TEXT INPUT BOX
object oMainPC = GetMainPC(oPC);
SetLocalObject(oMainPC, VAR_ENCHANTED_ITEM_OBJECT, oItem);
DisplayGuiScreen(oPC, "TextInputGUI", TRUE, "TextInput.xml");
// UPDATE ANY TEXTS REQUIRED
string sTITLETEXT = CGOLD + "Rename Item?";
string sNAMETEXT = "The Item's New Name Will Be:";
SetGUIObjectText(oPC, "TextInputGUI", "TitleText", -1, sTITLETEXT);
SetGUIObjectText(oPC, "TextInputGUI", "TextName", -1, sNAMETEXT);
SetGUIObjectText(oPC, "TextInputGUI", "TextNameInput", -1, GetName(oItem));
}
However, I recognise this may be much more than you first wanted to use (and is likely to require a lot of editing), so don’t worry to use it if it appears too complicated. I am just offering to show an approach that you may like to consider if and when feeling brave. …
Thanks, Lance.
Thanks Lance! I believe, as you do, that there may be some issues with the DisplayInputBox function, that may have to do with this not working for me. It is in this context I needed it to work, and in this context I tested it all the time, as being evident from what I’ve been saying/writing here.
However, the DisplayInputBox works well the way I use it, as long as the player doesn’t press “Okay” and not write anything. If the player does that, I think he has himself to blame in this case, and if he wants the character I ask the name for to be called “blank space” because he couldn’t follow a simple instruction, then so be it. If I then had used this name countless upon countless of times in my game, maybe the fault would have been mine, but as it is now, it is only mentioned one or maybe a few times, and then it’s no big deal, I think.
Don’t know if I am this adventurous to dare to try your approach with writing my own xml for this small thing. Maybe…but I don’t think so.
If I read your TextInput.xml correctly this STOPNAME only runs if you click Cancel? Or is that incorrect? Would I have to do some coding similar to this under OK Button perhaps?
Try this for the hell of it:
void main(string sPlayerAnswer)
{
object oPC = GetFirstPC(FALSE);
object oIP = CreateObject(OBJECT_TYPE_PLACEABLE, "plc_ipoint ", GetLocation(oPC), FALSE, "thenueh");
// ^
// This space is intentional. Leave it
if (sPlayerAnswer == " ") // <-- keep one space between quotes
{
SetCustomToken(1001, "Mike");
}
else
{
SetCustomToken(1001, sPlayerAnswer);
}
SetFirstName(oIP, "DM");
SetGlobalInt("playernamed", 1);
AssignCommand(oPC, ClearAllActions());
SetCutsceneMode(oPC);
AssignCommand(oIP, ActionStartConversation(oPC, "c_a_intro2"));
}