- I needed to add some books that some PCs needed to carry around for the resting system I am working on.
- I liked the way these books worked and always intended to have them for the new campaign, but wanted an easier way to add or remove the text data.
The original design by clubok required editing a TLK file and updating a 2da file so that the text could then be viewed. This has some advantages in that it is probably easier to write the text in the first place, but does, in my opinion, require too much extra work trying to keep track of stringrefs and having to update the 2da file with the various types of information it needs to work properly. I also believe that because my version is based in scripts, it is probably more flexible to the everyday builder. Each has its merits, and so I felt there was room for my version to be built, even if it is just me who ends up using it. ;)
One of the advantages was that I was able to add a "Picture Book", which is basically a book with pictures added. The pictures have to be added to the hak before build time, but after they are added, they can be selected to be viewed as if a page of a book. I included an example in the demo mod, but the pictures were not the best possible, as I did not want to spend too long on preparing them.
Not Bookworms - Bugs!
During my alteration of the code, it gave me a chance to learn a few more things about NWN2's tool set in general. Most of the time things went smoothly, but there were a few things that had me stumped for a while. Three things were related to some bugs in the engine:
1) Inventory Item Limit: The first problem that I encountered was that I was unable to limit the number of items that a placeable could hold. I wanted to reduce a bookcase's contents limit to no more than about ten items. Unfortunately, even though I changed the inventory limit figure, it would still default to a high number. I learned this is a known issue and will be dealt with soon.
2) SetFirstName(): The second issue that I encountered was to do with renaming an object using SetFirstName(). This function is supposed to work in a similar fashion as SetName() from NWN1. All my debug testing showed it to work, but the item would not change its name in game. It turned out the bug is that the name does change, but it is not updated on the item until after it has been moved within the PC's inventory.
3) GetHasSpell(): The last bug I encountered, which is probably the most frustrating in some ways, was the GetHasSpell() function. The function is supposed to check if a PC has a particular spell memorised. Unfortunately, it will say that a wizard has a Summon Creature spell memorised (for every level) even when they do not. I tried to exclude these particular spells from the check, but it prevented all the spells from working for a sorcerer. :(
Scripting Issues
There were a couple of scripting issues that came to light for me using NWN2, which I was not aware of when using NWN1:
1) Include Compiling: The first issue was the very important requirement to recompile scripts that rely on an include script, if the include is changed in any way. I don't ever recall having to do this when using NWN1, but it may be because I have done more with include scripts using NWN2 than I have done before when using NWN1. In this module I had three scripts that each used the include script called "alb_booktext". As this include file was where I write all the main text for the books in question, I soon came to realise that compiling and saving this single script to test my alterations in game was not enough. Basically, the three scripts that called upon the data from this include file also needed to be compiled and saved, even though there was nothing directly being changed in them! Now that I know this happens, I write it here as a reminder to myself and anybody else who may be wondering why a script is not applying updates one may have done to it.
2) Script Order: The second scripting issue I encountered was based upon the order in which my code was firing. At first I could not see any reasons why my loops were not working correctly. They would run through the loop for a while and then appear to drop out. It turned out that I was probably asking too much from the loop, and by altering where I did certain checks for the object being tested within the loop, it allowed the function to complete the loop without dropping out. The function in question is written below, and the original problem was that I was doing the if checks for the iCount number before checking if the PC had the spell. By moving the if checks until after the spell had been checked first, the script worked fine. Unfortunately, the "OR" commands do not show if I type the script and so I will have to rely on an image to show what I mean:
(Click on the image to enlarge it.)
The rest of the coding went fairly smoothly. I would like to thank diophant on the NWN2 forums for pointing me in the right direction with one of the scripts. Check out the ReadBook.PDF file that comes with the ReadBooks module for more information about setting up the books themselves. (Link to the left in My NWN2 Modules.)
No comments:
Post a Comment