View RSS Feed

Minty23185Fresh

A Neophyte Tackles the FG Extension - An XML Bag of Holding

Rate this Entry
A little bit of Lua and a lot of XMLÖ

Letís touch on variables. In a program, a variable is a place where data is stored. Variables have names, like x or myData or steve. Variables can have a type, which means they can only hold certain kinds of data, like a number, or a single letter of the alphabet. Some variables are very flexible and can hold anything, they are often referred to as objects. Luaís variables are untyped, they are very flexible, one can think of them as objects.

One might visualize variables as childrenís cubbies at the back of a classroom. These cubbies might have a type, e.g. they might only be for the childrenís coats. So when Jimmy tries to put his lunchbox in one of the cubbies, Mr. Program, the Cubby Monitor, sternly reminds him that the cubbies are only for coats.

Objects might be thought of as Bags of Holding. Some Bags might be restrictive and hold only one item, or one kind of item, other Bags might hold any number of items of any kind. Lets say we have a green Bag of Holding that only holds coins, weíll put our 3 gold, 1 silver and 2 copper pieces in it. Letís say we have a red Bag of Holding that only holds weapons, letís put our two daggers, our crossbow, and our jar containing gray ooze in it. And finally we have a black Bag of Holding, that holds anything. Letís put our chain mail, our torches and our red and green Bags in it. Letís put this dead goblin in there too.

The w3 schools web site tutorial states XML is a just data wrapped in tags. If youíve never experienced XML before now would be a good time to look at the first three or four lessons in an XML tutorial.

Now to wrap the items in the Bags, in some tagsÖ
Code:
<EQUIPMENT>
    <ITEM>green Bag of Holding</ITEM>
    <ITEM>3 gold coins</ITEM>
    <ITEM>1 silver coin</ITEM>
    <ITEM>2 copper coins</ITEM>
    <ITEM>red Bag of Holding</ITEM>
    <ITEM>2 daggers</ITEM>
    . . .
</EQUIPMENT>
By encompassing the data this way the what-contains-what information has been lost. By being a little more creative and using the power of XML the hierarchical relationship of the data can be preserved.

Code:
<EQUIPMENT>
    <MAGIC_ITEM type="Bag of Holding" color="black">
        <CORPSE>dead goblin</CORPSE>
        <ADVENTURE_GEAR>torches</ADVENTURE_GEAR>
        <ARMOR>chain mail<ARMOR>
        <MAGIC_ITEM type="Bag of Holding" color="red">
            <WEAPON>
                <JAR>gray ooze</JAR>
            </WEAPON>
            <WEAPON>crossbow</WEAPON>
            <WEAPON count="2">dagger</WEAPON>
        </MAGIC_ITEM>
        <MAGIC_ITEM type="Bag of Holding" color="green">
            <COINS>
              <GOLD count="3"></GOLD>
              <SILVER count="1"></SILVER>
              <COPPER count="2"></COPPER>
            </COINS>
        </MAGIC_ITEM>
    </MAGIC_ITEM>
</EQUIPMENT>
This isnít the only way to wrap the data in XML, it might not be the best way, but what I have tried to show here is, developers can use any tags they like. By being mindful, they can maintain the hierarchical relationship of the data, plus describe the properties of some items using XML attributes, e.g. the ďcolorĒ, ďtypeĒ, or ďcountĒ.

This isnít to say that in the context of FG, we can use any tags we like! The Smiteworks developers possess that freedom. Within the confines of FG, ruleset or extension developers, are limited to the tags defined by Smiteworks.

Detour: Big projects like FG are typically developed using Integrated Development Environments (IDEs), ones like Microsoftís .NET or the Unity Game Engine IDE. IDEs worth their salt have built in XML readers and writers so that details, like the tags, are of minor concern to the developer. The developer sets up all of the variables, objects, and other data, plus their containership within the program, then uses the writer to put all that data in an XML file. When the reader is used, it gets the data from the XML file and recreates the variables, objects and their relationships. It also populates those items with the data. Pretty slick!

Data inside a program has to be saved somewhere. To the hard drive, to the cloud, to somewhere. If it is not saved then when the program, i.e. Fantasy Grounds, is shut down the data will be lost and all of it must be reentered.

Knowing that the data, our inventory, has to be saved somewhere, letís hope it is on the hard drive, and that it is in a format we can view it in. Hopefully in XML.

Tactic: Put some unique inventory into FG, then search the hard disk for it.

Start Fantasy Grounds, create a new project, Iíll call mine Tomís Holdings. Choose the CoreRPG ruleset and then click Start. Create a Character, Iíll name mine Jimmy the Greek. Navigate to the Inventory tab, and add a couple items. A Bag of Holding, and Clark KentĎs Superman Cape. (Unique, right?)

05 - Core Inventory Screenshot.png

Close down FG.

I am going to use Notepad++ to search the hard disk for Superman Cape. Iíll start my search in the Fantasy Grounds data directory. Open up Notepad++ or whatever code editor youíve chosen to use. In Notepad++, in the main menu Iíll click Search, then Find in FilesÖ In the Find in Files dialog Iíll enter Superman Cape and set the Directory to my FG data folder. The location of my data folder is highlighted in blue in the screen shot below (your data folder might be different).

05 - Superman Search.png

Click the Find All button. After a lengthy search. Notepad++ found it. Mine is in the db.xml file residing in the campaigns\Tomís Holding subfolder of the FG data folder.

In Notepad++ if I double click the line that the Search string was found in (not the file name, the actual string), Notepad++ will load the file and place the editing location on that line.

Here is what the <inventorylist> section of my db.xml looks like:
Code:
<inventorylist>
  <id-00001>
    <carried type="number">1</carried>
    <count type="number">1</count>
    <isidentified type="number">1</isidentified>
    <name type="string">Bag of Holding</name>
    <weight type="number">1</weight>
  </id-00001>
  <id-00002>
    <carried type="number">1</carried>
    <count type="number">1</count>
    <isidentified type="number">1</isidentified>
    <location type="string">Bag of Holding</location>
    <name type="string">Clark Kent's Superman Cape</name>
    <weight type="number">1</weight>
  </id-00002>
</inventorylist>
That sure doesnít look like either of my XML examples above. Note that there are two items (id-00001 & 2). Each item has the proper data in the <name> field and the proper <weight>. Iím not sure what some of the other items are all about. Note that the Superman Cape also has a <location>, and it appropriately is in the Bag of Holding!

Above I mentioned that some IDEs have XML readers and writers that preserve internal object (and variable) names. Between blog posts I am going to try to find out if FGís internal, Lua object names are the same as the XML tags in the db.xml file.

Until next time keep on role playing.

Submit "A Neophyte Tackles the FG Extension - An XML Bag of Holding" to Digg Submit "A Neophyte Tackles the FG Extension - An XML Bag of Holding" to del.icio.us Submit "A Neophyte Tackles the FG Extension - An XML Bag of Holding" to StumbleUpon Submit "A Neophyte Tackles the FG Extension - An XML Bag of Holding" to Google Submit "A Neophyte Tackles the FG Extension - An XML Bag of Holding" to Facebook Submit "A Neophyte Tackles the FG Extension - An XML Bag of Holding" to Twitter

Comments

Log in

Log in