PDA

View Full Version : Storing Data



Ardem
June 22nd, 2012, 04:22
I am still getting my head wrapped around FG's Database controls. My desire is to create some GM Tools which is for a random weather system and random encounters.

To do this I am creating a new button which launches the 'random' windowclass. (ManagementScript_Desktop.lua)

Upon launching a windowclass, (I am using the foundation charsheet for a simple example) it should create the control class fields automatically.??

So when you modify, in this case, the labelstring is should save it to the DB. The only thing I believe I am missing in all this is whether I have to define the DB or the fields prior, and how to go about this.

The window currently displays, the data field allow entry, however the data on close does not save to the DB.

I know this must be simple to you guys, I have managed to change charsheet data and add fields, but this is different.




<?xml version="1.0" encoding="iso-8859-1"?>
<root version="2.0">

<windowclass name="random">
<frame>charsheet</frame>
<placement>
<size>
<width>525</width>
<height>611</height>
</size>
<position>
<x>410</x>
<y>90</y>
</position>
</placement>
<minimize />
<nodelete />
<playercontrol />
<sheetdata>
<genericcontrol name="overviewframe">
<bounds>15,20,480,70</bounds>
<frame>
<name>sheetgroup</name>
</frame>
</genericcontrol>

<labeledstring name="name" source="random.name">
<anchored>
<to>overviewframe</to>
<position>insidetopleft</position>
<offset>15,10</offset>
<size>
<width>450</width>
<height>20</height>
</size>
</anchored>
<anchorto>overviewframe</anchorto>
<height>20</height>
<label>name</label>
<tabtarget>
<next>race</next>
<prev>appearance</prev>
</tabtarget>
</labeledstring>

<closebutton />
</sheetdata>
</windowclass>
</root>

Moon Wizard
June 22nd, 2012, 18:58
When you are opening a window using a windowreferencefield, windowlist or Interface.openWindow and if the control/function opening the window specified a data source, any field controls will automatically create their underlying database nodes.

A couple other notes/questions:
* How are you creating a window with this class? I didn't see any code that referenced this class.
* "labeledstring" is actually a template, which I believe points to a stringfield control type, if you want to understand more about what is happening.

Regards,
JPG

Ardem
June 23rd, 2012, 07:03
Thanks Moon for your quick reply.

To launch the window all I am doing is adding a button on the ManagementScript_Desktop.lua


DesktopManager.registerStackShortcut("button_random", "button_random_down", "Random", "random");


This launches the window. I am assuming that this function launches the class. Am I missing something at this point?

I have changed labelstring to a stringfieldX, but this has not saved the data either. Without error messages I am not sure what I am doing wrong.

Moon Wizard
June 23rd, 2012, 08:19
When you launch the window using the function you described it's trying to create and use a node "root.random" as the datasource for the resulting window. The stringfield should not have a source tag, and should end up creating a "root.random.name" node with a string type.

After opening the window, type /save at the chat entry line, then look at the db.xml file to see what gets saved.

If that fails, you can try posting your extension to see if someone can take a look.

Regards,
JPG

Ardem
June 26th, 2012, 12:42
Ok tried the /save and checked the db.xml and there was no data saved. I removed the data source as well hoping it would show up in the root.rmcrandom.name

The extension is for the Rolemaster ruleset. Most of the code in it at the moment is for the dropdown boxes to work.


I have attached the ext, if someone can let me know what I am doing wrong. I am sure it is a elementary mistake on my behalf.

kairos
June 26th, 2012, 13:39
There are two ways you could approach this. If you are loading a random subset of a data set, you could look at the module classes for inspiration (the .xml files beginning with "reference_"). The approach here would be to build your data into a module or even leverage existing RM module data (like monster entries) for your random encounter generator. I'd probably explore this route first, especially if the data already exists in a module. Then, all you'd have to do is the code for randomizing it in a windowclass which would display it.

The other approach I would consider would be to create a RandomManager script and build your data out as tables which your windowclass would then reference. I'd create a tabbed window like the charsheet or npc class and have random weather and monsters on separate tabs. Each tab would contain a windowlist which loads instances of a random_monster or random_weather windowclass (the data for which is randomly loaded from you data tables).

Keep us posted on your progress.

Moon Wizard
June 26th, 2012, 21:01
Your call to DesktopManager.registerStackShortcut does not specify a database note to write the data to. If you look at the lines for the Combat tracker and Characters button registration above, you'll see that they have another parameter that specifies the data path.

Regards,
JPG

Ardem
June 27th, 2012, 04:51
Thanks Moon, you were spot on. I should of reviewed the registerStackShortcut function.


function registerStackShortcut(iconNormal, iconPressed, tooltipText, className, recordName)
function createFunc()
createStackShortcut(iconNormal, iconPressed, tooltipText, className, recordName);
end

if window == nil then
table.insert(delayedCreate, createFunc);
else
createFunc();
end
end

function createStackShortcut(iconNormal, iconPressed, tooltipText, className, recordName)
local control = window.createControl("desktop_stackitem", tooltipText);

table.insert(stackcontrols, control);

control.setIcons(iconNormal, iconPressed);
control.setValue(className, recordName or "");
control.setTooltipText(tooltipText);

updateControls();
end

That made it a little clearer in how the db is accessed. Well as clear as smeared mud for me I hope this helps anyone else that is easily confused like myself.

@Kairos The reason I am opting for a db access is I want to keep the last defined weather, so this can be used in the random roll. EG If previous weather was raining, increase the likelihood that is is still raining. Seasons will also play a factor, and if your rolling per day for weather, I aiming to get some realistic weather pattern runs.