View Single Post
Mathias
Senior Member
Lone Wolf Staff
 
Join Date: May 2005
Posts: 13,213

Old January 5th, 2010, 09:19 AM
Quote:
Originally Posted by djc664 View Post
Would it be possible to have a simple number field that tells you how many pages a spell takes up from the memorized ones? I.e. tracking which book it's in and how many pages are left may be manual, but how many pages each take are automatically shown...?
This will be easy, and it's a great idea.

In fact, since I won't get to this for a little while, I'll show you how to do something like it:

Go to the develop menu, and make sure that "Enable Data File Debugging" is checked.

Create a new character, add a level or two of wizard, and go to the wizard tab. Go to the spellbook and add a few spells, then on any of the spells, right click, and select "Show Debug Tags for XXX". Move the window that pops up out of the way, close the spellbook, and then memorize the same spell you're looking at. Look at the memorized copy's debug tags, too.

What's actually happening behind the scenes is that each spell in your spellbook is added to the hero, and when you memorize spells, it gives you a list of all the spells you have in your spellbook. Actually memorizing the spell creates a new copy of that spell, but some of the tags are different, which tells the program that it's a Wizard memorized spell instead of a spell in the spellbook or a Cleric memorized spell (which would be important for a multiclass character).

Okay, looking at the tags for the two spells, you'll note that the level is stored as an sLevel tag, and the spellbook copy has "Spellbook.cHelpWiz" - which identifies it as a spell in the spellbook. Those are the tags we're going to use to find the number of pages currently used. Also note the component tags, and decide which seems to be most specific to the type of thing you're looking at. In this case, it's component.BaseSpell.

Now, on to the editor. Create a new editor file (file...new), then go to the gear tab within the editor, and press "New (Copy)", and select "Wizard's Spellbook (blank)" from that list. Give it a new unique ID (like "gSplBook", and change the name so it's distinct from the previous version (like "Spellbook, Wizard's (blank, counting)").

Press the "Eval Scripts" button near the top right, and "Click to add a new Eval Script". At the top, change the phase to "Render" (since we're only creating display information, we should run it very late in the sequence). Change the priority to 10000, because there's some other things happening very early in the Render phase that we don't want to interfere with.

Now, on to the script.

This is how to search through all the things of a type in HeroLab (or specifically, how to search through all the spells that are in a wizard's spellbook):

Code:
foreach pick in hero from BaseSpell where "Spellbook.cHelpWiz"
Now that we're finding all those spells, let's calculate how many pages each one takes:

Code:
 
pages += eachpick.tagvalue[sLevel.?]
For each pick we find, extract the numerical value of the sLevel tag on that pick, and add it to a total value.

Now to modify that for cantrips (since they take up one page):

Code:
 
pages += minimum(eachpick.tagvalue[sLevel.?], 1)
Add the minimum of that numerical value or 1 to our total.

Putting that together (this includes declaring a variable to store things in and closing the foreach):

Code:
 
var pages as number
 
foreach pick in hero from BaseSpell where "Spellbook.cHelpWiz"
  pages += minimum(eachpick.tagvalue[sLevel.?], 1)
  nexteach
So, when that ends, pages stores the total number of pages that would be required to store all the spells in your spellbook. Now let's do something with it, like change the name of the thing:

Code:
 
field[livename].text = "Spellbook, Wizard's (" & pages & " pages used)"
That will incorporate the value of the pages variable we've been accumulating into the name of the spellbook. If you want to change the name, be careful to keep quotes on both ends of any text and to use an & character between each separate thing (like a change from text to a variable, and then another & when the variable's been entered, and you want some more text).

Putting all that together for easy copying:

Code:
 
var pages as number
 
foreach pick in hero from BaseSpell where "Spellbook.cHelpWiz"
  pages += minimum(eachpick.tagvalue[sLevel.?], 1)
  nexteach
 
field[livename].text = "Spellbook, Wizard's (" & pages & " pages used)"
Admittedly, each spellbook you add to your inventory will show the same total, but it's good enough.

Now, save this item in the editor, press "Test Now!" at the top left, and then try buying this new spellbook version for your test character. Make sure it displays the number properly, and watch things change as you add or delete spells from your spellbook.
Mathias is offline   #5 Reply With Quote