Log in

View Full Version : How to get the databasenode value of the "total" control of a specific skill?



gandhi39
April 6th, 2012, 02:55
Usually on the skills tab of a character sheet we have a visible list (as defined by data_common.lua) showing all skills and their specifics.

For each skill we have a "total", usually set by a "total" control on charsheet_skills.xml.


OK. Now, on another tab I made a linkednumber control (called "speed") which I want to express "the athletics skill total value" -1.

Can you help me?

Moon Wizard
April 7th, 2012, 06:54
You have to navigate the character record database hierarchy in order to get the information.

Here is a rough idea of the approach:

* Within the onInit for the linked control, you will need to find the database node for the Speed total, and use an onUpdate callback function to get updates.

* From linked control, determine top level character node (Ex: nodeChar = window.getDatabaseNode()) (may vary depending on your sheet layout)
* Navigate to skill list database node. (Ex: nodeSkillList = nodeChar.getChild("skilllist"))
* Check each skill node for the correct skill. (Ex: for k,v in pairs(nodeSkillList.getChildren()) do if (DB.getValue(v, "label", "") == "Speed") then v.onUpdate = ...your callback function...; end end)

There are probably some similar examples spread around in the other rulesets, just look for the onUpdate callback initializations.

One other consideration is that the Speed skill node may not exist yet, depending on your initialization order; so you may need to create it.

Regards,
JPG

gandhi39
April 7th, 2012, 09:35
Thanks for the answer, but I'm not sure if you understood what I'm trying to do.

My gamesystem is a bit similiar to d20 3.5. There are skills. And "Athletics" is one of them. "Athletics" is listed on data_common.lua, so it apears on the skills tab of the character sheet.

But "Speed" is not a skill. I made a separate linkednumber control called "speed" on the main tab. This control needs a script, that I don't know how to do.

What I want is for "speed" to be equal to "the Athletics skill total value -1".

I hope you can help me.

Zeus
April 7th, 2012, 11:14
@gandhi39: It maybe slightly easier to assist you with some guidance if we could see the windowclass XML/LUA code you are using.

If you could post up the windowclass code we can then best suggest how you might go about achieving the functionality your after.

gandhi39
April 7th, 2012, 21:40
data_common.lua (still with some unused stuff)


abilities = {
"agility",
"intelect",
"presence",
"senses",
"vigor",
"will",
"dexterity"
};

-- Skill properties
skilldata = {
["Acrobacia"] = {
stat = "dexterity",
armorcheckmultiplier = 1
},
["Alerta"] = {
stat = "dexterity"
},
["Atletismo"] = {
stat = "dexterity",
armorcheckmultiplier = 1
},
["Blefe"] = {
stat = "dexterity"
},
["Busca"] = {
stat = "dexterity"
},
["Combate à Distância"] = {
stat = "dexterity",
armorcheckmultiplier = 1
},
["Combate Próximo Armado"] = {
stat = "dexterity",
armorcheckmultiplier = 1
},
["Combate Próximo Desarmado"] = {
stat = "dexterity",
armorcheckmultiplier = 1
},
["Concentração"] = {
stat = "dexterity"
},
["Conhecimento Místico"] = {
stat = "dexterity"
},
["Diplomacia"] = {
stat = "dexterity"
},
["Empatia"] = {
stat = "dexterity"
},
["Esquiva"] = {
stat = "dexterity",
armorcheckmultiplier = 1
},
["Furtividade"] = {
stat = "dexterity",
armorcheckmultiplier = 1
},
["Idiomas"] = {
stat = "dexterity"
},
["Iniciativa"] = {
stat = "dexterity",
armorcheckmultiplier = 1
},
["Intimidação"] = {
stat = "dexterity"
},
["Logro de Mecanismos"] = {
stat = "dexterity",
armorcheckmultiplier = 1
},
["Resistência Física"] = {
stat = "dexterity",
armorcheckmultiplier = 1
},
["Resistência Mental"] = {
stat = "dexterity"
},
["Sobrevivência"] = {
stat = "dexterity"
},
}



charsheet_skills.xml


<root version="2.6">
<windowclass name="charsheet_skilllistitem">
<sizelimits>
<minimum>
<height>18</height>
</minimum>
</sizelimits>
<script file="scripts/charsheet_skilllistitem.lua" />
<sheetdata>
<windowreferencefield name="shortcut">
<anchored>
<right>
<anchor>right</anchor>
<offset>-2</offset>
</right>
<top>
<anchor>top</anchor>
<offset>2</offset>
</top>
<size>
<width>20</width>
<height>20</height>
</size>
</anchored>
<icon>
<normal>button_openwindow</normal>
<empty>button_emptytarget</empty>
<pressed>button_emptytarget</pressed>
</icon>
<allowdrop />
</windowreferencefield>

<linkednumber name="total">
<anchored>
<right>
<parent>shortcut</parent>
<anchor>left</anchor>
<offset>-8</offset>
</right>
<top>
<anchor>top</anchor>
<offset>2</offset>
</top>
<size>
<width>32</width>
<height>16</height>
</size>
</anchored>
<frame>
<name>modifier</name>
<offset>5,5,5,5</offset>
</frame>
<font>sheetnumber</font>
<readonly />
<displaysign />
<rollable />
<source>
<name>abilitymod</name>
<op>+</op>
</source>
<source>
<name>skillmod</name>
<op>+</op>
</source>
<script>
function onDoubleClick(x, y)
Comm.throwDice( "dice", {"d20"}, getValue(), "Jogada de Per&#237;cia")
end

function onDragStart(button, x, y, dragdata)
dragdata.setType("dice");
dragdata.setDieList({ "d20" });
dragdata.setNumberData(getValue());
dragdata.setDescription("Jogada de Per&#237;cia");

return true;
end
</script>
</linkednumber>

.
.
.

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


charsheet_skilllist.lua


function onInit()
-- Construct default skills
constructDefaultSkills();
end

function onSortCompare(w1, w2)
if w1.label.getValue() == "" then
return true;
elseif w2.label.getValue() == "" then
return false;
end

return w1.label.getValue() > w2.label.getValue();
end

-- Create default skill selection
function constructDefaultSkills()
-- Collect existing entries
local entrymap = {};

for k, w in pairs(getWindows()) do
local label = w.label.getValue();

if DataCommon.skilldata[label] then
if not entrymap[label] then
entrymap[label] = { w };
else
table.insert(entrymap[label], w);
end
end
end

-- Set properties and create missing entries for all known skills
for k, t in pairs(DataCommon.skilldata) do
local matches = entrymap[k];

if not matches then
local wnd = NodeManager.createWindow(self);
if wnd then
wnd.label.setValue(k);
matches = { wnd };
end
end
end
end


charsheet_main.xml


<root version="2.6">
<windowclass name="charsheet_main">
<placement>
<size>
<width>252</width>
<height>611</height>
</size>
</placement>
<nodelete />
<sheetdata>

.
.
.

<!-- OTHER STATS -->
<genericcontrol name="otherstats">
<bounds>15,350,415,236</bounds>
<frame>
<name>sheetgroup</name>
</frame>
</genericcontrol>

.
.
.

<numberfield name="deslocamento">
<anchored>
<to>actions</to>
<position>belowleft</position>
<offset>0,7</offset>
<size>
<width>32</width>
<height>20</height>
</size>
</anchored>
<frame>
<name>modifier</name>
<offset>5,5,5,5</offset>
</frame>
<font>sheetnumber</font>
</numberfield>

.
.
.

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



I gave you english terms before. By my system is in brazilian portuguese. In fact the "speed" I talked about is the "deslocamento" control presented in the code.

As it is, I am filling it up manually. But it would be nice if I could automate the process. It should express the "Atletismo" skill total value -1.

I omitted some of the code, because of the size. Hope it's clearer now.

gandhi39
April 7th, 2012, 21:58
The ruleset is base on the foundation ruleset. (I can't manage to post images correctly)
https://imageshack.us/photo/my-images/844/mainhv.jpg/
https://imageshack.us/photo/my-images/38/skillsy.jpg/

Here, "Deslocamento" (in squares) should be 9-1 = 8. But it is reduced to 4 because of heavy armor.

Moon Wizard
April 9th, 2012, 19:45
I understood what you were doing, and the advice still holds.

You basically need to:
1. In Speed field onInit, find the Athletics skill (or create the skill if not created yet).
2. In Speed field onInit, set up a callback on the Athletics skill total so that your Speed field is notified when it changes. (i.e. onUpdate = <callback function name>)
3. Set the Speed field as readonly. (It's much more complicated to synch both ways)
4. In Speed field callback, get the value of the Athletics skill total node, subtract one, and use setValue to set the value.

Regards,
JPG