Joined: 02 Feb 2006 Posts: 1094 Location: Southern Central USA
Posted: Wed Feb 21, 2007 3:18 am Post subject: The worker.src speech bug.
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:
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:
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.
Author
Message
Yukiko
Joined: 02 Feb 2006 Posts: 1094 Location: Southern Central USA
Posted: Wed Feb 21, 2007 4:17 am Post subject:
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.
Author
Message
Yukiko
Joined: 02 Feb 2006 Posts: 1094 Location: Southern Central USA
Posted: Wed Feb 21, 2007 4:43 am Post subject:
Here are more scripts that have speech enable errors like the one above:
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?
Author
Message
Yukiko
Joined: 02 Feb 2006 Posts: 1094 Location: Southern Central USA
Posted: Wed Feb 21, 2007 4:06 pm Post subject:
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.