Author Topic: SetListenPattern()  (Read 1017 times)

Legacy_BenHar70

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
SetListenPattern()
« on: July 22, 2010, 12:01:47 pm »


               Hello all,

I desperately need help with a module I am building that I use within schools.  I want an NPC to ask a series of questions.  The PC will type in there answer and then the next question will be asked.  I have a fully working module for maths and wanted to expand this for a higher level of maths.  The problem:  when the PC gets to the 10th question the NPC stops listening??  works fine before that but as soon as I add more questions it fails.  Anyone know why? 

I have been building NWN modules for education for a while and usually use listenpattern for passwords but I thoought this would be a good way to get the answers out of the pupils.

This is my first post and I can't seem to add the relevant files or upload the mod for people to look at.  I hope i have explained myself properly'Posted

Any help would be greatly appreciated.
               
               

               
            

Legacy_BenHar70

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
SetListenPattern()
« Reply #1 on: July 22, 2010, 12:07:08 pm »


               Here are my scripts:



OnUserDefined:

void main()

{

   object oSelf = OBJECT_SELF;

   object oPC = GetFirstPC();

   int iPattern = GetListenPatternNumber();

   int iQuest = GetLocalInt(oPC, "iQvar");

   int iQnum = GetLocalInt(oPC, "iQuestion");



   if(GetIsListening(oSelf))

   {

if((iPattern == 517) && (iQuest == 2) && (iQnum == 17))

       {

           SpeakString(" Well done ");

           ClearAllActions();

           PrintString("**  **");

           WriteTimestampedLogEntry("**  Time  **");

           PrintString("**  Question 3a : 17.24 X 30  **");

           PrintString("**   Answer 3a  : 517.2  **");

           PrintString("**  **");

           SetLocalInt(oPC, "iQuestion", 18);

           SetListening(oSelf, FALSE);

           GiveGoldToCreature(oPC, 30);

           AssignCommand(oSelf, ActionStartConversation(oPC, "con_drow_qset2"));

       }

       if((iPattern == 518) && (iQuest == 2) && (iQnum == 18))

       {

           SpeakString(" Well done ");

           ClearAllActions();

           PrintString("**  **");

           WriteTimestampedLogEntry("**  Time  **");

           PrintString("**  Question 3b : 2.735 X 40  **");

           PrintString("**   Answer 3b  : 109.4  **");

           PrintString("**  **");

           SetLocalInt(oPC, "iQuestion", 19);

           SetListening(oSelf, FALSE);

           GiveGoldToCreature(oPC, 30);

           AssignCommand(oSelf, ActionStartConversation(oPC, "con_drow_qset2"));

       }

       if((iPattern == 519) && (iQuest == 2) && (iQnum == 19))

       {

           SpeakString(" Well done ");

           ClearAllActions();

           PrintString("**  **");

           WriteTimestampedLogEntry("**  Time  **");

           PrintString("**  Question 3c : 14.45 X 50  **");

           PrintString("**   Answer 3c  : 722.5  **");

           PrintString("**  **");

           SetLocalInt(oPC, "iQuestion", 20);

           SetListening(oSelf, FALSE);

           GiveGoldToCreature(oPC, 30);

           AssignCommand(oSelf, ActionStartConversation(oPC, "con_drow_qset2"));

       }

       if((iPattern == 520) && (iQuest == 2) && (iQnum == 20))

       {

           SpeakString(" Well done ");

           ClearAllActions();

           PrintString("**  **");

           WriteTimestampedLogEntry("**  Time  **");

           PrintString("**  Question 3d : 3.127 X 30  **");

           PrintString("**   Answer 3d  : 93.81  **");

           PrintString("**  **");

           SetLocalInt(oPC, "iQuestion", 21);

           SetListening(oSelf, FALSE);

           GiveGoldToCreature(oPC, 30);

           AssignCommand(oSelf, ActionStartConversation(oPC, "con_drow_qset2"));

       }

       if((iPattern == 521) && (iQuest == 2) && (iQnum == 21))

       {

           SpeakString(" Well done ");

           ClearAllActions();

           PrintString("**  **");

           WriteTimestampedLogEntry("**  Time  **");

           PrintString("**  Question 3e : 0.6 ÷ 20  **");

           PrintString("**   Answer 3e  : 0.03  **");

           PrintString("**  **");

           SetLocalInt(oPC, "iQuestion", 22);

           SetListening(oSelf, FALSE);

           GiveGoldToCreature(oPC, 30);

           AssignCommand(oSelf, ActionStartConversation(oPC, "con_drow_qset2"));

       }

       if((iPattern == 522) && (iQuest == 2) && (iQnum == 22))

       {

           SpeakString(" Well done ");

           ClearAllActions();

           PrintString("**  **");

           WriteTimestampedLogEntry("**  Time  **");

           PrintString("**  Question 3f : 0.4 ÷ 80  **");

           PrintString("**   Answer 3f  : 0.005  **");

           PrintString("**  **");

           SetLocalInt(oPC, "iQuestion", 23);

           SetListening(oSelf, FALSE);

           GiveGoldToCreature(oPC, 30);

           AssignCommand(oSelf, ActionStartConversation(oPC, "con_drow_qset2"));

       }

        if((iPattern == 523) && (iQuest == 2) && (iQnum == 23))

       {

           SpeakString(" Well done ");

           ClearAllActions();

           PrintString("**  **");

           WriteTimestampedLogEntry("**  Time  **");

           PrintString("**  Question 3g : 0.4 ÷ 60  **");

           PrintString("**   Answer 3g  : 0.006  **");

           PrintString("**  **");

           SetLocalInt(oPC, "iQuestion", 24);

           SetListening(oSelf, FALSE);

           GiveGoldToCreature(oPC, 30);

           AssignCommand(oSelf, ActionStartConversation(oPC, "con_drow_qset2"));

       }

        if((iPattern == 524) && (iQuest == 2) && (iQnum == 24))

       {

           SpeakString(" Well done ");

           ClearAllActions();

           PrintString("**  **");

           WriteTimestampedLogEntry("**  Time  **");

           PrintString("**  Question 3h : 0.8 ÷ 50  **");

           PrintString("**   Answer 3h  : 0.016  **");

           PrintString("**  **");

           SetLocalInt(oPC, "iQuestion", 25);

           SetListening(oSelf, FALSE);

           GiveGoldToCreature(oPC, 30);

           AssignCommand(oSelf, ActionStartConversation(oPC, "con_drow_qset2"));

       }

        if((iPattern == 525) && (iQuest == 2) && (iQnum == 25))

       {

           SpeakString(" Well done ");

           ClearAllActions();

           PrintString("**  **");

           WriteTimestampedLogEntry("**  Time  **");

           PrintString("**  Question 3i : 14 ÷ 0.2  **");

           PrintString("**   Answer 3i  : 70  **");

           PrintString("**  **");

           SetLocalInt(oPC, "iQuestion", 26);

           SetListening(oSelf, FALSE);

           GiveGoldToCreature(oPC, 30);

           AssignCommand(oSelf, ActionStartConversation(oPC, "con_drow_qset2"));

       }

        if((iPattern == 526) && (iQuest == 2) && (iQnum == 26))

       {

           SpeakString(" Well done ");

           ClearAllActions();

           PrintString("**  **");

           WriteTimestampedLogEntry("**  Time  **");

           PrintString("**  Question 3j : 35 ÷ 0.5  **");

           PrintString("**   Answer 3j  : 70  **");

           PrintString("**  **");

           SetLocalInt(oPC, "iQuestion", 27);

           SetListening(oSelf, FALSE);

           GiveGoldToCreature(oPC, 30);

           AssignCommand(oSelf, ActionStartConversation(oPC, "con_drow_qset2"));

       }

        if((iPattern == 527) && (iQuest == 2) && (iQnum == 27))

       {

           SpeakString(" Well done ");

           ClearAllActions();

           PrintString("**  **");

           WriteTimestampedLogEntry("**  Time  **");

           PrintString("**  Question 3k : 27 ÷ 0.3  **");

           PrintString("**   Answer 3k  : 90  **");

           PrintString("**  **");

           SetLocalInt(oPC, "iQuestion", 28);

           SetListening(oSelf, FALSE);

           GiveGoldToCreature(oPC, 30);

           AssignCommand(oSelf, ActionStartConversation(oPC, "con_drow_qset2"));

       }

       if((iPattern == 528) && (iQuest == 2) && (iQnum == 28))

       {

           SpeakString(" Well done ");

           ClearAllActions();

           PrintString("**  **");

           WriteTimestampedLogEntry("**  Time  **");

           PrintString("**  Question 3l : 24 ÷ 0.4  **");

           PrintString("**   Answer 3l  : 60  **");

           PrintString("**  **");

           SetLocalInt(oPC, "iQuestion", 29);

           SetLocalInt(oPC, "iQvar", 3);

           SetListening(oSelf, FALSE);

           GiveGoldToCreature(oPC, 30);

           AssignCommand(oSelf, ActionStartConversation(oPC, "con_drow_qset2"));

       }

       if(iPattern == 999)

       {

           SpeakString(" Sorry, that's not the correct answer.  Try again. ");

           TakeGoldFromCreature(30, oPC, TRUE);

       }

   }





}



Script placed in conversation actions taken when I want PC to answer

void main()

{

   object oSelf = OBJECT_SELF;

   object oPC = GetFirstPC();



//  Decimals

   string sAnswer3a = "517.2";

   string sAnswer3b = "109.4";

   string sAnswer3c = "722.5";

   string sAnswer3d = "93.81";

   string sAnswer3e = "0.03";

   string sAnswer3f = "0.005";

   string sAnswer3g = "0.006";

   string sAnswer3h = "0.016";

   string sAnswer3i = "70";

   string sAnswer3j = "70";

   string sAnswer3k = "90";

   string sAnswer3l = "60";



   SetListenPattern(oSelf, sAnswer3a, 517);

   SetListenPattern(oSelf, sAnswer3b, 518);

   SetListenPattern(oSelf, sAnswer3c, 519);

   SetListenPattern(oSelf, sAnswer3d, 520);

   SetListenPattern(oSelf, sAnswer3e, 521);

   SetListenPattern(oSelf, sAnswer3f, 522);

   SetListenPattern(oSelf, sAnswer3g, 523);

   SetListenPattern(oSelf, sAnswer3h, 524);

   SetListenPattern(oSelf, sAnswer3i, 525);

   SetListenPattern(oSelf, sAnswer3j, 526);

   SetListenPattern(oSelf, sAnswer3k, 527);

   SetListenPattern(oSelf, sAnswer3l, 528);

   SetListenPattern(oSelf, "**", 999);



   SetListening(oSelf, TRUE);

}
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
SetListenPattern()
« Reply #2 on: July 22, 2010, 12:18:43 pm »


               most probably you forgot to set LocalInt(oPC, "iQuestion") to 27 and 28 in conversation

otherwise, try to add there some debugging message or run it throught nwn debugger to see whats are the variables and you should be able to locate the issue
               
               

               
            

Legacy_BenHar70

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
SetListenPattern()
« Reply #3 on: July 22, 2010, 12:31:01 pm »


               Thanks for the reply ShaDo0oW.  

I dont set "iQuestion" in the conversation - its set when the question is answered correctly on the UserDefined script then the conversation file is fired and I have a short Text Appears When script to display the next question :

if((iPattern == 526) && (iQuest == 2) && (iQnum == 26))



{



SpeakString(" Well done ");



ClearAllActions();



PrintString("** **");



WriteTimestampedLogEntry("** Time **");



PrintString("** Question 3j : 35 ÷ 0.5 **");



PrintString("** Answer 3j : 70 **");



PrintString("** **");



SetLocalInt(oPC, "iQuestion", 27);



SetListening(oSelf, FALSE);



GiveGoldToCreature(oPC, 30);



AssignCommand(oSelf, ActionStartConversation(oPC, "con_drow_qset2"));



}



Yeah, thought about adding debug messages.  I just wondered if anyone would know why it has worked before but when I add a larger set of questions it fails.



NWN Debugger????  I must be an idiot because I've never used this - where? how?



thanks again for the help
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
SetListenPattern()
« Reply #4 on: July 22, 2010, 01:42:52 pm »


               NWN Debugger is very powerfull tool.



To use it, first go to Script Editor Options and check "Generate debug information when compiling scripts" checkbox.



Then add "SpawnScriptDebugger();" line somewhere in your script (put it under void main for start).

Compile script and then get back into options an uncheck it (you might do that later when you find the problem). Then just run game via F9, btw for me it didnt worked in fullscreen (large resolution), so if you had problems with it, try to run nwn in window.
               
               

               
            

Legacy_BenHar70

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
SetListenPattern()
« Reply #5 on: July 22, 2010, 01:50:19 pm »


               Thanks ShaDo0oW.  



I'll try this tonight.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
SetListenPattern()
« Reply #6 on: July 23, 2010, 07:11:40 am »


               

BenHar70 wrote...

Thanks for the reply ShaDo0oW.
I dont set "iQuestion" in the conversation - its set when the question is answered correctly on the UserDefined script then the conversation file is fired and I have a short Text Appears When script to display the next question :
if((iPattern == 526) && (iQuest == 2) && (iQnum == 26))

{

SpeakString(" Well done ");

ClearAllActions();

PrintString("** **");

WriteTimestampedLogEntry("** Time **");

PrintString("** Question 3j : 35 ÷ 0.5 **");

PrintString("** Answer 3j : 70 **");

PrintString("** **");

SetLocalInt(oPC, "iQuestion", 27);

SetListening(oSelf, FALSE);

GiveGoldToCreature(oPC, 30);

AssignCommand(oSelf, ActionStartConversation(oPC, "con_drow_qset2"));

}

Yeah, thought about adding debug messages. I just wondered if anyone would know why it has worked before but when I add a larger set of questions it fails.

NWN Debugger???? I must be an idiot because I've never used this - where? how?

thanks again for the help




I hope the code above is not your Text Appeares script.  Not knowing how your conversation if formated.  I can only guess that the problem.  I think the problem in in your text appeares script.    Check the node that gives the question and all parent conversation  nodes.   If you do not find the solution there, Will need to know more about how the conversation is layed out. 
               
               

               
            

Legacy_BenHar70

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
SetListenPattern()
« Reply #7 on: July 23, 2010, 11:16:10 am »


               Cheers Lightfoot8,

The above code is part of a series of IF statements OnUserDefined.  I checked all the conversation nodes and The Text Appears When Scripts for the questions are fine, this will display question 26 (sc_ta_q26):

int StartingConditional()

{

   // Inspect local variables

   if(!(GetLocalInt(GetPCSpeaker(), "iQuestion") == 26))

       return FALSE;

   return TRUE;

}



This all works fine if my question sets are less than 10 questions (bizarre)- I have a fully working module with 25 questions which are split into 5 question sets.  I now want to build a module with larger question sets but my NPC's who ask the questions stop listening after 9 questions?????



Question Master (NPC) conversation:



- [OWNER] Q28)  24/0.4 = ?   -Text Appears When script(sc_ta_28)

    - I'll type in my answer[END DIALOGUE]   - Actions Taken Script(see below)

- [OWNER] Q27)  27/0.3 = ?   -  -Text Appears When script(sc_ta_27)

    - I'll type in my answer[END DIALOGUE]   -  Actions Taken Script(see below)



This will check the listenpattern for the answer just typed in - Actions Taken Script:

void main()

{

   object oSelf = OBJECT_SELF;



//  Decimals

   string sAnswer3a = "517.2";

   string sAnswer3b = "109.4";

   string sAnswer3c = "722.5";

   string sAnswer3d = "93.81";

   string sAnswer3e = "0.03";

   string sAnswer3f = "0.005";

   string sAnswer3g = "0.006";

   string sAnswer3h = "0.016";

   string sAnswer3i = "70";

   string sAnswer3j = "70";

   string sAnswer3k = "90";

   string sAnswer3l = "60";



   SetListenPattern(oSelf, sAnswer3a, 517);

   SetListenPattern(oSelf, sAnswer3b, 518);

   SetListenPattern(oSelf, sAnswer3c, 519);

   SetListenPattern(oSelf, sAnswer3d, 520);

   SetListenPattern(oSelf, sAnswer3e, 521);

   SetListenPattern(oSelf, sAnswer3f, 522);

   SetListenPattern(oSelf, sAnswer3g, 523);

   SetListenPattern(oSelf, sAnswer3h, 524);

   SetListenPattern(oSelf, sAnswer3i, 525);

   SetListenPattern(oSelf, sAnswer3j, 526);

   SetListenPattern(oSelf, sAnswer3k, 527);

   SetListenPattern(oSelf, sAnswer3l, 528);

   SetListenPattern(oSelf, "**", 999);



   SetListening(oSelf, TRUE);

}



I just find it strange that my NPC's stop listening @ a certain point - i've used these types of scripts before for puzzles and passwords and never had a problem but when I want to ask a larger series of questions it fails.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
SetListenPattern()
« Reply #8 on: July 25, 2010, 08:58:45 pm »


               sorry for the delay in responce. 
I was really looking for the text appears when on the parent conversation node.
 
-What is here. and is there a Text appeares condition to this parent node. 
- -[OWNER] Q28) 24/0.4 = ? -Text Appears When script(sc_ta_28)
-- I'll type in my answer[END DIALOGUE] - Actions Taken Script
-- [OWNER] Q27) 27/0.3 = ? - -Text Appears When script
- -I'll type in my answer[END DIALOGUE] - Actions Taken Script(see below)


If it is not in the condition of the parent node. It my be in the fact that you keep setting your listening paterns over and over again.  I do not know how the game stores the patterns.  in setting them over and over you may be just adding to the list every time they are added instead of replaceing them.  Either way it is a bad practice to set them over and over.  You may want to find a way to set them only once.  the onSpawn of the npc would be good or at least a DoOnce control.

Another thing in your script i question is your OnUserDefined script.  I do not see a filter for if it is called from an event other then the OnConversation. I can only assume that you only have that one event calling the UserDefined event.  Still a filter for other events would not hurt. 

In truth I do not see why you dont do most of this, in the OnUserDefined event. 
- When called from OnSpawn set up the listening patterns.(a call for this event would have to be added )
- When called from OnConversation Check to see if it is the right answer. and fire the conversation back up.  

If done that way.
 You could make custom tokens for the current question to be asked and make the conversation just one node. 

I am also guessing that with the lack of other checks and the use of GetFirstPC() that this is a single player module.  
               
               

               


                     Modifié par Lightfoot8, 25 juillet 2010 - 08:00 .
                     
                  


            

Legacy_BenHar70

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
SetListenPattern()
« Reply #9 on: July 26, 2010, 12:49:55 pm »


               Thanks for the help Lightfoot8,

I appreciate what your saying about setting patterns over and over so i placed the patterns in the OnSpawn script - it works '<img'>



Again appreciate what you say about checks but my module is for single player and is very linear and these scripts are only ever fired OnConversation.  Basically you are ported to an area where you fight some bad guys and then have to answer a series of questions.  When you answer all questions correctly you then go onto the next section, etc, etc.



I found the problem '<img'>  With question set 1 the answer to q4 is "0.1"  and the answer for q12 is "0.1".  I had created 2 listenPatterns for "0.1" - doh

with question set 2 the answer to q7 was "1.45" and the answer to q12 ... wait for it ... was "1.45" again I had created 2 patterns - coincedence or what - had to be on q12 twice.  I now only create 1 pattern for these answers and call it twice OnUserDefined - works a treat



Thanks a lot to ShaDoOoW and especially Lightfoot8.  I've tidied up my code a bit since this and really appreciate your help.

Cheers