It is currently Wed Oct 15, 2008 11:16 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: The worker.src speech bug.
PostPosted: Tue Feb 20, 2007 11:18 pm 
Offline

Joined: Thu Feb 02, 2006 1:41 pm
Posts: 1154
Location: Southern Central USA
OK, I looked and looked and searched and could not find the thread under which I thought this bug was posted. Then it occurred to me that it had never been posted here.

Datus and I were discussing the worker.src speech problem tonight on the phone. This has bothered me ever since he emailed me about it. For the benefit of those who may not have been privy to his emial (which I hope are all of you *grins*) I am posting the bug and the fix here.

The bug:
In the POL 0.95 Distro there's an AI script named worker.src. This script is supposed to respond to various speech events such as [NPCName} + "train" or "hire" and so on. The problem is that it doesn't. I have looked at this before but was unable to determine the problem. Well, as I said I was discussing this with Datus and decided to look again.

I admit I was on a mission with this one. After fixing the pack animal problem this one was sticking in my crop and I just had to get it working.
*smiles wryly*
Yeah it was a matter of pride I guess.

The bug originates in the very beginning of the script. It's in the EnableEvents function call. Here is the code that is in error:
Code:
program CastleGuard()
  run_script_to_completion("NPCKeeper", me);
  drop_anchor();
  EnableEvents(SYSEVENT_SPEECH + SYSEVENT_ENGAGED + SYSEVENT_DISENGAGED + SYSEVENT_DAMAGED);


Now I have looked at this over and over along with all the other parts of the script dealing with speech and never saw the problem.

So I asked myself "What AI script do I know of that handles speech properly?" The answer was tamed.src.

Upon opening tamed.src I first looked at the case statement that parses the speech and found nothing unusual there. So I then looked at the function EnableMainEvents and found this curious item, there is an additional parameter passed along with the EnableEvent function call when enabling speech. There's an integer that's passed along. That integer is the listening range. You will note in the above code snippet from worker.src there is no such parameter passed.

The fix for this is by far easier than that for the pack animal one. Simply change the above code to this:
Code:
program Worker()
  run_script_to_completion("NPCKeeper", me);
  drop_anchor();
  EnableEvents(SYSEVENT_SPEECH, 3);
  EnableEvents(SYSEVENT_ENGAGED + SYSEVENT_DISENGAGED + SYSEVENT_DAMAGED);


Voilla! It now works.

Note also the change to the name from CastleGuard to Worker. This has no effect on functionality. It's just good programming practice to not be lazy when borrowing script templates for use in other scripts.

I have not taken the time to research the other EnableEvents function calls to see if they are properly formatted. If anyone sees a problem with the other ones please post the fix here.

Once again anyone running POL 0.95 Distro converted to POL 0.97 should take note of this bug.

_________________
Sincerely,
Yukiko

I know you think you understand what you thought I said but what you heard is not exactly what I meant.

Titus 2:13


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 21, 2007 12:17 am 
Offline

Joined: Thu Feb 02, 2006 1:41 pm
Posts: 1154
Location: Southern Central USA
I found a similar bug in the employed.src script.

Look in that script at line 531. Change that line to:
Code:
  EnableEvents(SYSEVENT_SPEECH, 8);


I figured 8 was a good range as this is a script for a human NPC in your employ rather than an animal NPC as in the tamed script.

_________________
Sincerely,
Yukiko

I know you think you understand what you thought I said but what you heard is not exactly what I meant.

Titus 2:13


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 21, 2007 12:43 am 
Offline

Joined: Thu Feb 02, 2006 1:41 pm
Posts: 1154
Location: Southern Central USA
Here are more scripts that have speech enable errors like the one above:

townPerson.src
pirate.src
person.src
mainLoopMeek.inc
mainLoopGood.inc
escortee.src

Once again if you are using converted 0.95 Distro scripts take note of these fixes.

_________________
Sincerely,
Yukiko

I know you think you understand what you thought I said but what you heard is not exactly what I meant.

Titus 2:13


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 21, 2007 5:44 am 
Offline
User avatar

Joined: Tue Sep 19, 2006 6:27 am
Posts: 58
*profound joy and excitement*

Damn you're good... and all this time I was worried I'd have to learn Spanish or Deutsch or something. :)

So in EnableEvents(SYSEVENT_SPEECH, 3); I'm assuming the integer is tile distance?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 21, 2007 12:06 pm 
Offline

Joined: Thu Feb 02, 2006 1:41 pm
Posts: 1154
Location: Southern Central USA
That's correct as far as I remember. Enabling the speech event requires a range parameter. I am almost certain other events require that as well to enable them but I haven't had time yet to research it.
*laughs*
You can tell I have never written any scripts that use events.

Oh and no I am not that good, trust me. I can't whip out an entire boat package in one evening like Austin can. It's just that I was irritated that I couldn't figure that one out and like I said it was a matter of pride.

_________________
Sincerely,
Yukiko

I know you think you understand what you thought I said but what you heard is not exactly what I meant.

Titus 2:13


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Style based on FI Subice by phpBBservice.nl