PDA

View Full Version : A plea regarding the database



Stv
May 28th, 2020, 00:18
I'm currently struggling a bit with the FG database...
Can someone give me a pointer on how you'd store and then get the information back from a table i.e
if I had a table :
name1 value 1
name2 value2
name 3 value 3
etc

what would be the preferred/best way to store this in the database?

Cheers, Steve.

Trenloe
May 28th, 2020, 08:46
Is this a dynamic table or a table with fixed rows?

Does the data need to be individually accessed, or is it just for reference?

If you have a dynamic table - essentially a list (these are all over the place in FG), these can be displayed in the windowlist control: https://fantasygroundsunity.atlassian.net/wiki/spaces/FGU/pages/4162373/windowlist

The underlying database structure will be something like the following (this is a skill list from PF2):

<skilllist>
<id-00001>
<armorcheckmultiplier type="number">0</armorcheckmultiplier>
<label type="string">Arcana</label>
<misc type="number">0</misc>
<prof type="number">0</prof>
<showonminisheet type="number">1</showonminisheet>
<stat type="number">0</stat>
<state type="number">0</state>
<statname type="string">intelligence</statname>
<total type="number">0</total>
</id-00001>
<id-00002>
<armorcheckmultiplier type="number">0</armorcheckmultiplier>
<label type="string">Occultism</label>
<misc type="number">0</misc>
<prof type="number">3</prof>
<proflevel type="string">trained</proflevel>
<showonminisheet type="number">1</showonminisheet>
<stat type="number">0</stat>
<state type="number">0</state>
<statname type="string">intelligence</statname>
<total type="number">3</total>
</id-00002>
<id-00003>
<armorcheckmultiplier type="number">0</armorcheckmultiplier>
<label type="string">Diplomacy</label>
<misc type="number">0</misc>
<prof type="number">0</prof>
<showonminisheet type="number">1</showonminisheet>
<stat type="number">-1</stat>
<state type="number">0</state>
<statname type="string">charisma</statname>
<total type="number">-1</total>
</id-00003>
<id-00004>
<armorcheckmultiplier type="number">0</armorcheckmultiplier>
<label type="string">Nature</label>
<misc type="number">0</misc>
<prof type="number">0</prof>
<showonminisheet type="number">1</showonminisheet>
<stat type="number">2</stat>
<state type="number">0</state>
<statname type="string">wisdom</statname>
<total type="number">2</total>
</id-00004>
</skilllist>

Adding a new row to the table automatically adds a new <id-XXXXX> intermediate node to the database structure.

You can use the API in the windowlist (linked above) to navigate data, but this relies on the windowlist being open. You're best navigating this data in code using the database - https://fantasygroundsunity.atlassian.net/wiki/spaces/FGU/pages/4063529/DB and https://fantasygroundsunity.atlassian.net/wiki/spaces/FGU/pages/4063650/databasenode

Info on the database here: https://fantasygroundsunity.atlassian.net/wiki/spaces/FGU/pages/4161654/Ruleset+-+Database

Stv
May 28th, 2020, 09:38
Thanks for replying Trenloe,
The structure you've posted is pretty much what I'm after, I just need to be able to create/reference it from withng a lua function. That's the bit I'm struggling with (I've never been very good with database manipulation, even going back years ago to Dataease :O
I'll have another look at it and see if I can figure it out.

Cheers, Steve.

Trenloe
May 28th, 2020, 10:51
Don't think of FG as a "database" in terms of a relational database. It's basically a flat file. So you're operating against a clearly visible hierarchy.

Adding things to an existing entry is usually with createChild - where you create a child node of an existing node. See here: https://fantasygroundsunity.atlassian.net/wiki/spaces/FGU/pages/4063529/DB#createChild or here: https://fantasygroundsunity.atlassian.net/wiki/spaces/FGU/pages/4063650/databasenode#createChild

To create a new intermediate node in the skilllist example above, use newChildNode = DB.createChild(soruceNode)

Where newChildNode is the new node you've created - it'll be an intermediate node <id-XXXX> in the DB structure. And soruceNodeis the skilllist node identifier.

Then you can use newChildNode (which is a databasenode object) to create new children nodes - like name, or value, etc.. Info on the databasenode object here: https://fantasygroundsunity.atlassian.net/wiki/spaces/FGU/pages/4063650/databasenode

Stv
May 28th, 2020, 17:30
Thanks again Trenloe,
I think I get the gist of that :)
I'll have a mess around and see if I can get things to work out.

Cheers, Steve.