PDA

View Full Version : Code Problem



Kelendor
January 17th, 2015, 04:24
Here is the challenge I'm currently working on:

I'm trying to understand how FG adds all the various bonuses on the character sheet.
I have two goals I am working towards: I'd like to add a level/2 bonus to skills like 4th edition does and have a trained check box (once ticked) add +5 to a skill. I have the checkbox and the tool tip already done, but I can't seem to find where the math for total skill bonus is calculated.


This is from 4th edition record_char_main.xml:
<number_linked name="levelbonus">
<anchored to="level" position="righthigh" offset="50,0" width="32" height="20" />
<displaysign />
<readonly />
<frame name="fieldlight" offset="7,5,7,5" />
<source>
<name>level</name>
<op>+</op>
</source>
<script>
function onSourceUpdate()
setValue(math.floor(calculateSources() / 2));
end
</script>
</number_linked>

And this is from record_char_skills.xml
<simplenumber name="level" source="...levelbonus">
<anchored width="32" height="20">
<top offset="2" />
<right parent="rightanchor" anchor="left" relation="relative" offset="-5" />
</anchored>
<displaysign />
<hideonvalue>0</hideonvalue>
<disabled />
</simplenumber>
<number_charskillfield_static name="stat">
<anchored width="32" height="20">
<top offset="2" />
<right parent="rightanchor" anchor="left" relation="relative" offset="-5" />
</anchored>
<script>
function update(statname)
setValue(DB.getValue(window.getDatabaseNode(), "...abilities." .. statname .. ".bonus", 0));
end
</script>

As can be seen in BOLD these are the only things I can find for calculations but they seem arcane. No comments anywhere. I don't see a definition of "floor" or of "bonus" and thus can't really try to edit them.
I've even pasted those lines into the appropriate files but was not successful.

In d20 modern record_char_skills.xml there is a similar line:
<number_charskillfield_static name="stat">
<anchored width="32" height="20">
<top offset="2" />
<right parent="rightanchor" anchor="left" relation="relative" offset="-5" />
</anchored>
<script>
function update(statname)
setValue(DB.getValue(window.getDatabaseNode(), "...abilities." .. statname .. ".bonus", 0));
end
</script>
</number_charskillfield_static>

but again I have no definition of "bonus" and thus can't figure out how to add a piece to that. That is if that is actually the line that adds up the skill total to begin with.

As mentioned earlier I have a check box implemented "trained" (+5) and would like to add half the level of the character as a bonus.
It's already seems to be tracked as "level" on the main tab of the character sheet (record_char_main.xml)

I also checked under scripts: char_totalwithability.lua, char_skill.lua, char_skilllist.lua

for k, v in ipairs(aAbility) do
local nAbilityBonus = ActorManager2.getAbilityBonus(rActor, getAbility(k));
if k == 1 and nMaxMod and nMaxMod >= 0 then
if nAbilityBonus > nMaxMod then
nAbilityBonus = nMaxMod;
end
end
nBonus = nBonus + nAbilityBonus;
end

In Bold - I tried doing a straight +5 or plus anything but nothing changed it. Even setting it to a number with no other additions didn't change it.

Any help would be appreciated.
thanks.

dulux-oz
January 17th, 2015, 04:40
General Notes:

Have you read the LUA Reference Website (https://www.lua.org/manual/5.2/manual.html) - floor() is an LUA function and is described there.

A line like:


setValue(DB.getValue(window.getDatabaseNode(), "...abilities." .. statname .. ".bonus", 0));

Reads as follows: From the Database (DB) take the value (getValue()) of the window's databaseNode's childNode and set this Control's value to that value.
The childNode is given by the string: "...abilities." .. statname .. ".bonus", with statname being a variable and "ability" and "bonus" being literals - in other words, if you were to look at the raw data in the database then under the Node that the window is referencing there would be a Node called (for example) "ability.strength.bonus".

What you need to do when beginning to code in FG is be prepared to jump from file to file and from Object to Object investigating how it all hangs together - from your question I think you're doing this now (I'm also assuming you know what an Object is? And are familiar with the concepts of Encapsulation, Inheritance and Polymorphism? If not, check out Wikipedia for those terms in relation to Object Orientated Coding)

So, the best tool I've found to help with all this jumping around is Notepad++ (free download) because when I stated out with FG Coding I opened up ALL the files in the CoreRPG Ruleset (Notepad++ does each one as a separate Tab) and I could then simply do a global search on each term as I encountered it.

In particular, off the top of my head, and without thinking about the ramifications too hard, you could simply use a DB.setValue() on the relevant "bonus" node when you check your checkbox - but you'd have to investigate what else was seting that value in the DB and take those into account as well.

Hope that gets you started.

Cheers

Trenloe
January 17th, 2015, 04:51
Firstly, the sections you tried to show in bold haven't shown up in bold. But, I'll make a guess at to what you're referring to.

A few pointers:


math.floor is base LUA code: https://www.lua.org/manual/5.1/manual.html#pdf-math.floor
The line where .bonus is contained is actually a window.getDatabaseNode. More info on that here: https://www.fantasygrounds.com/refdoc/windowinstance.xcp#getDatabaseNode Also check the database section of the ruleset modification guide for info on the database node format: https://www.fantasygrounds.com/modguide/database.xcp


At the core of this is getting to understand that 99% of data that is displayed in the FG GUI is stored in the FG campaign database - for PCs this is stored in the <charsheet> section of the database. Open the db.xml file in a campaign directory and see how the data is stored. For instance, the database entry pointed to by "...abilities." .. statname .. ".bonus" will be take you to a specific entry in the campaign database, for example: charsheet.id-00001.abilities.charisma.bonus. Here is an example section from the 4E demo campaign A Tale of Dinor:


<charsheet>
<id-00001>
<abilities>
<charisma>
<bonus type="number">0</bonus>
<bonusmodifier type="number">0</bonusmodifier>
<check type="number">0</check>
<score type="number">10</score>
</charisma>

Now, back to your underlying goal. In the 4E ruleset, the LUA script you want to look at is campaign\scripts\manager_char.lua, in particular the getSkillValue function. This gets various data from the underlying <charsheet> database and uses these the calculate the final value for a skill. If the "trained" field for a particular skill is selected then 5 is added to the total value. The levelbonus database entry is populated on the main character sheet page - which you have already found in your post below in the <number_linked name="levelbonus"> control.

Hope all of the above helps...