PDA

View Full Version : Updating Character Sheet field within Manager_Action



MadBeardMan
May 27th, 2017, 12:02
Morning All,

Been stuck on this the last few nights, it's the final puzzle that I need to solve to be able to move on for the WOiN (What's Old is New) ruleset.

When a Skill check is performed, the dice roll and report back and explode and are spot on, just one thing I need to do, if Luck Dice are used I need to reduce the 'Luck Dice Pool' that's attached to the character sheet (off the .id node).

Within the onDiceLanded there's no access to the DB it would seem, so an emails to JPG and he suggested adding a ResultHandler, which I've done (see below), now I'm struggling here, I have access to the rSource which in turn I can find the actor, but when I query the DB I get the string 'luckdicepool' returned and not the number 3.

Here's the code and against each Print line I've added what's displayed in the console.


function onInit()
Interface.onHotkeyActivated = actionHotkey;

ActionsManager.registerResultHandler("skill", onRoll);
end

function onRoll(rSource, rTarget, rRoll)
print "Help me Obi Wan";
if rSource then
local sActorType, sActorNode = ActorManager.getTypeAndNodeName(rSource);
print (sActorType); // Shows 'PC'
print (sActorNode); // Shows 'charsheet.id-0002'

myActor = ActorManager.getActor(sActorType, sActorNode);

if myActor then
print "I have an Actor"; // Shows this.
else
print "NO Actor";
end

print(DB.getValue("id-00002", "luckdicepool", 0)); // Shows the string "luckdicepool" not the 3 I'm expecting
else
print ("No source");
end
end

Aside from this I've also noticed this stops the dice result from displaying, I'm not worried about that yet, just want to access the characters data....

So is there an Obi-wan who can help?

Cheers
Col

Trenloe
May 27th, 2017, 13:20
Please post an example of your database where luckdicepool is stored.

MadBeardMan
May 27th, 2017, 13:39
Here's the character data using the tree, is from the db.xml and I've cut it down so you can see the nodes but not the data (such as defenses)


<charsheet>
<id-00002>
<age type="string">16</age>
<attributes>
</attributes>
<careerlist>
</careerlist>
<carry>
</carry>
<carrymodifier type="number">0</carrymodifier>
<climb>
</climb>
<climbmodifier type="number">0</climbmodifier>
<defenses>
</defenses>
<derived_stats>
</derived_stats>
<descriptor type="string">An ambidextrous Felan burglar who plays classical music</descriptor>
<encumbrance>
</encumbrance>
<encumbrancestatus type="string">Lightly encumbered</encumbrancestatus>
<exploitlist>
</exploitlist>
<grade type="number">5</grade>
<health type="number">0</health>
<homeworld type="string">Unknown</homeworld>
<init type="number">4</init>
<initiative>
</initiative>
<initiativemodifier type="number">0</initiativemodifier>
<inventorylist>
</inventorylist>
<jumphmodifier type="number">0</jumphmodifier>
<jumpvmodifier type="number">0</jumpvmodifier>
<luckdicepool type="number">3</luckdicepool>

Cheers

Trenloe
May 27th, 2017, 13:45
Use DB.getValue("charsheet.id-00002", "luckdicepool", 0)

MadBeardMan
May 27th, 2017, 13:51
Use DB.getValue("charsheet.id-00002", "luckdicepool", 0)

Chap,

Already tried that, tried passing the 'sActorNode' in as the 1st argument as well, still same result.


Runtime Notice: Reloading ruleset
Script Notice: Help me Obi Wan
Script Notice: pc
Script Notice: charsheet.id-00002
Script Notice: I have an Actor
Script Notice: luckdicepool


Can't figure out why it's returning the text rather than actual value.

Trenloe
May 27th, 2017, 14:09
EDIT: See post #9 below for the reason why the above wasn't working.

Try DB.getValue("charsheet.id-00002.luckdicepool") or DB.getValue(sActorNode .. ".luckdicepool")

MadBeardMan
May 27th, 2017, 14:14
It looks like there's an issue with DB.getValue.

Try DB.getValue("charsheet.id-00002.luckdicepool") or DB.getValue(sActorNode .. ".luckdicepool")

Now you sir are brilliant!


print(DB.getValue(sActorNode, "luckdicepool", 0));
print(DB.getValue(sActorNode .. ".luckdicepool", 0));

Which means I can reset it (using DB.setValue()).


Runtime Notice: Reloading ruleset
Script Notice: Help me Obi Wan
Script Notice: pc
Script Notice: charsheet.id-00002
Script Notice: I have an Actor
Script Notice: luckdicepool
Script Notice: 3

Just leaves me with the issue, because I'm overriding onRoll, is there a way I can tell it to run the CoreRPG onRoll as all I wanted to do was this bit, I presume if not, I'll just copy onRoll from CoreRPG and modify it.

Cheers!

Trenloe
May 27th, 2017, 14:19
Just leaves me with the issue, because I'm overriding onRoll, is there a way I can tell it to run the CoreRPG onRoll as all I wanted to do was this bit, I presume if not, I'll just copy onRoll from CoreRPG and modify it.
In theory you could call it using <packagename>.onRoll... but the FG standard is to include all action handlers in the LUA file for the action in question. So I'd recommend copying the CoreRPG onRoll into your manager_action_xxxxxxx.lua script and modifying it.

Trenloe
May 27th, 2017, 14:23
Actually, there's not an issue with DB.getValue (https://www.fantasygrounds.com/refdoc/DB.xcp#getValue), the documentation states:


Parameters
sourcenode (string (or databasenode))
A data node identifier path (or a databasenode object) representing the target node
subpath (string) [optional]
If the first parameter has type databasenode, then this parameter specifies the relative data node identifier path from the specified node object.
default (...) [optional]
The value(s) to be returned if getValue fails. (node does not exist; or non-value node)

As "sourcenode" is not a database node, but a string, so "subpath" wouldn't be used and the "luckdicepool" was becoming the "default". As charsheet.id-00002 was a non-value node then the default would be returned.

So, working as designed. Nice to know. :)

MadBeardMan
May 27th, 2017, 14:42
Actually now I know how all the 'rSource' to access the Character data works, I don't need a new resulthandler, I can create a simple function and call this when the dice results are shown.

Cheers @Trenloe, I've been battling this for a few nights!

MadBeardMan
May 27th, 2017, 14:44
Actually, there's not an issue with DB.getValue (https://www.fantasygrounds.com/refdoc/DB.xcp#getValue), the documentation states:



As "sourcenode" is not a database node, but a string, so "subpath" wouldn't be used and the "luckdicepool" was becoming the "default". As charsheet.id-00002 was a non-value node then the default would be returned.

So, working as designed. Nice to know. :)

That's ace to know, I've spent so many hours going around in circles that at times perhaps the best thing to have done is to perhaps put tools down and ask here.....