PDA

View Full Version : template with sources, not showing up?



celestian
February 20th, 2017, 22:30
So, I've been poking around the 5e ruleset and saw how they did some templates to auto-calculate AC so I decided to use it also. Right now this does nothing but print output to the debug/console. The problem is the "sources" variable is nil. If I try and access sources["defenses.ac.armor"] it just reports an error in the console (nil).

This should update the value anytime ability scores are updated (specifically dexterity).

I'm guessing I'm missing an important requirement for this to work properly (sources actually show up).



<template name="number_chartotalac2">
<number_chartotal>
<description textres="armorclass" />
<font>reference-b-large</font>
<modifiersize>mini</modifiersize>
<modifierfield>defenses.ac.temporary</modifierfield>
<source><name>defenses.ac.armor</name><op>+</op></source>
<source><name>defenses.ac.shield</name><op>+</op></source>
<source><name>defenses.ac.misc</name><op>+</op></source>
<script>
function onInit()
print ("template_char.xml, onInit");
super.onInit();
DB.addHandler(DB.getPath(window.getDatabaseNode(), "abilities"), "onChildUpdate", onSourceUpdate);
end

function onClose()
print ("template_char.xml, onClose");
DB.removeHandler(DB.getPath(window.getDatabaseNode (), "abilities"), "onChildUpdate", onSourceUpdate);
end

function onSourceUpdate()
print ("template_char.xml, onSourceUpdate");
Debug.console("template_char.xml", "onSourceUpdate", sources);
end
</script>
</number_chartotal>
</template>



this is the use of the template:



<number_chartotalac2 name="ac2" source="defenses.ac.total">
<readonly />
<anchored to="combattitle" width="30" height="40">
<top anchor="bottom" offset="10" />
<left anchor="center" offset="-55" />
</anchored>
<frame name="acicon" offset="2,0,2,4" />
</number_chartotalac2>

Trenloe
February 20th, 2017, 22:51
sources is a table of database nodes, hence why you can't just output the data to the console. Info on database nodes here: https://www.fantasygrounds.com/refdoc/databasenode.xcp

You can use the getNodeName interface to convert the databasenode into it's string representation for debugging purposed. e.g. sources["defenses.ac.armor"].getNodeName()

How sources work is coded in the CoreRPG ruleset: common\scripts\number_linked.lua

celestian
February 20th, 2017, 23:04
sources is a table of database nodes, hence why you can't just output the data to the console. Info on database nodes here: https://www.fantasygrounds.com/refdoc/databasenode.xcp

You can use the getNodeName interface to convert the databasenode into it's string representation for debugging purposed. e.g. sources["defenses.ac.armor"].getNodeName()

How sources work is coded in the CoreRPG ruleset: common\scripts\number_linked.lua

I'll take a look at the mentioned links. Thanks for the tips.

This quest originated when I tried to "setValue(10 + calculateSources());" and the console would report that "calculateSources" was nil.

"local sArmor = sources["defenses.ac.armor"].getNodeName();" also generates a index global sources nil value also.

Moon Wizard
February 20th, 2017, 23:18
The main thing you need to do is have the CoreRPG and 5E rulesets unpacked. Then, when you encounter a tag you don't recognize and isn't listed in the FG developer reference, then you search for that tag across CoreRPG, 5E and your ruleset to see where it is defined. (template, font, icon, windowclass, etc.)

I use Notepad++ for doing my Lua coding, since it has a good multi-file search and a decent comparison plug-in.

Cheers,
JPG

Trenloe
February 20th, 2017, 23:24
I use Notepad++ for doing my Lua coding, since it has a good multi-file search and a decent comparison plug-in.
Me too.

@celestian - if you haven't checked it out already, this thread has some great pointers: https://www.fantasygrounds.com/forums/showthread.php?19033-Modifying-the-3-5e-PFRPG-ruleset It's written for 3.5E but all of the principals apply to 5E.

celestian
February 20th, 2017, 23:46
The main thing you need to do is have the CoreRPG and 5E rulesets unpacked. Then, when you encounter a tag you don't recognize and isn't listed in the FG developer reference, then you search for that tag across CoreRPG, 5E and your ruleset to see where it is defined. (template, font, icon, windowclass, etc.)

I use Notepad++ for doing my Lua coding, since it has a good multi-file search and a decent comparison plug-in.

Cheers,
JPG

I am infact doing just that ;) I can't imagine searching through all these files looking for a variable that matches by hand. Big fan of notepad++ (do a lot of perl/python/java/etc for work).

There is obviously something different in the way I did it and 5e... the 5e one works, mine doesn't. I am just trying to trace where I flunked out. Just not sure where because I practically copy/pasted it.

celestian
February 21st, 2017, 02:15
So, figured it out. Another rookie mistake.

I created a template for myself called "number_modifier" which obviously overlapped the actual one which was used about 4 templates deep in the above options I posted.

Renamed it to something else and walla, things work. I figured it out by "flattening" the 5e ruleset and mine (just diffed the base.xml, merged, copied over my files) and when I started doing the search down the line of all the templates to look for a cause I noticed it popped up in my _adnd.xml template file and it dawned on me... that shouldn't be there ;) It's in the CoreRPG ruleset.

After this I am considering just using the flatten'd version of the ruleset since I am going to be making a lot of changes and mostly don't expect the 5e ruleset will be of much use (other than an awesome base to start with for me). It just less confusing with 1 layer (CoreRPG) than 2.

Skills/ability checks/saves, initiative they are all a really different in AD&D than 5e. I've had to tweak the tracker, sheets and several other core things that will probably be hard to reconcile down the road if they update 5e drastically. The main reason I used it is because it's really "feature" rich to rob from even tho the "rules" are not the same. Its a lot more to work with than some of the other rulesets I looked at.

No reason to reinvent the wheel!

Trenloe
February 21st, 2017, 03:05
It just less confusing with 1 layer (CoreRPG) than 2.
Are you saying that you're not going to use any layering at all? i.e. you're going to take a the current CoreRPG and 5E and merge them together and then do all of your modifications against that code base?

celestian
February 21st, 2017, 04:24
Are you saying that you're not going to use any layering at all? i.e. you're going to take a the current CoreRPG and 5E and merge them together and then do all of your modifications against that code base?

Just merge 5e, not CoreRPG. Right now I don't think I need to change anything within CoreRPG and if I do it should be minor so a layered approach should work for it.