PDA

View Full Version : Modifying Characteristic Bonus Calculation in the MyQuest extension



FlightlessScotsman
April 21st, 2017, 17:59
I've been using a customized MyQuest extension for some time now to make BRP behave more like Magic World with mostly success, but there is one niggling issue I haven't been able to figure out.

Starting on line 256 in the "MyScript.lua" file there is a function for calculating characteristic bonuses for skills. Numerous times I've attempted to edit this section to make the characteristic bonus calculate according to Magic World rules (which is Characteristic/2) but no matter what I've done, it reverts to the default BRP characteristic bonus calculation.

Here is the default code:

function getCategoryBonus(influence,characteristic)
if influence=="Primary" then
return characteristic - 10;
elseif influence=="Secondary" then
if characteristic>10 then
return math.floor(characteristic/2) - 5;
else
return math.ceil(characteristic/2) - 5;
end
elseif influence=="Negative" then
return 10 - characteristic;
end
return 0;
end

And here is the code I'm attempting to replace it with:

function getCategoryBonus(influence,characteristic)
if influence=="Primary" then
return math.ceil(characteristic/2);
end
return 0;
end

I'm certainly no code expert, so I suspect that I'm probably doing something wrong with the syntax, but the console doesn't seem to throw any errors, it just always defaults to the top calculation method, whenever I enable characteristic bonuses in the options.

Any help would be appreciated.

FlightlessScotsman
April 21st, 2017, 19:43
Update (sort of)

On the plus I was able to verify that my code is correct.

On the downside I had to directly edit a script in the Basic Roleplaying.pak, namely "charsheet_skilllist.lua with my code to get the character sheet to force it to recognize new calculation function. I gather that this means I will lose any edits any time I happen to run an update and the BRP ruleset will get overwritten with the server version. I considered just copying the .pak file and renaming it something like BRP-MW.pak, but if I do that I won't be able to load any of the BRP modules that come with the ruleset.

If anybody has any great insight on how to force charsheet_skilllist.lua to respect the overrides in the MyQuest extension I'd love to hear it.

Moon Wizard
April 21st, 2017, 22:10
You have to redefine the control or template which defines the script within your extension, and include the updated script file under a "scripts" subdirectory in the extension.



<windowclass name="charsheet_skills" merge="join">
<sheetdata>
<windowlist name="skilllist">
<script file="scripts/charsheet_skilllist.lua" />
</windowlist>
</sheetdata>
</windowclass>


Regards,
JPG

FlightlessScotsman
April 21st, 2017, 23:01
You have to redefine the control or template which defines the script within your extension, and include the updated script file under a "scripts" subdirectory in the extension.



<windowclass name="charsheet_skills" merge="join">
<sheetdata>
<windowlist name="skilllist">
<script file="scripts/charsheet_skilllist.lua" />
</windowlist>
</sheetdata>
</windowclass>


Regards,
JPG

With respect to the MyQuest extension that ships with the BRP ruleset that I'm trying to edit, there are two editable files: the "MyScript.lua" script file and "extension.xml" file. Where exactly would the code block you post go then? Under the window classes heading?

The code of the extension.xml file is as such:

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Copyright SmiteWorks USA, LLC., 2010 -->
<root version="2.0">
<properties>
<name>Magic World Campaign Extension</name>

<author>SmiteWorks USA, LLC., 2010</author>
<description>Sample campaign extension for the Basic Roleplaying ruleset.</description>

<exclusiongroup>BRPGameline</exclusiongroup>

<ruleset>
<name>Basic Roleplaying</name>
</ruleset>
</properties>

<base>

<!-- icons -->
<icon name="cs_logo" file="Custom.png" />

<!-- frames -->
<framedef name="myq_sheet">
<bitmap file="myq_sheet.png" />
<topleft rect="0,0,12,12" />
<top rect="12,0,322,12" />
<topright rect="334,0,12,12" />
<left rect="0,12,12,325" />
<middle rect="12,12,322,325" />
<right rect="334,12,12,325" />
<bottomleft rect="0,337,12,12" />
<bottom rect="12,337,322,12" />
<bottomright rect="334,337,12,12" />
</framedef>

<!-- window classes -->

<!-- tabcontrol template -->

<!-- charsheet templates -->

<!-- script file -->
<script name="MyQScript" file="scripts/myqscript.lua" />

</base>
</root>

FWIW, BRP is not built off of CoreRPG, so I'm not sure if that changes anything.

Thanks for your help.

Moon Wizard
April 22nd, 2017, 22:59
Yes, you could place the windowclass modification in that part of the extension, and you would need to add the modified charsheet_skilllist.lua to the scripts directory in the extension as well.

Regards,
JPG

FlightlessScotsman
April 23rd, 2017, 05:05
Excellent. I'll try to test this out when I get home. Thanks for your help. @Moon Wizard

EDIT:
It finally calculates the characteristic bonus correctly, so thank you. It does throw a script error and a script warning in the console. I'm not sure if they are fatal errors or not so I figure I'll post them here:

Script Error: [string "scripts/charsheet_skilllist.lua"]:306: attempt to call global 'getWindows' (a nil value)
The Code block in question at line 306 looks like such (the offending line bolded and underlined)


function checkdefaultskills()
-- create default skills
local skilldata = LineManager.getLine().Skills;
local winlist = {};

for k, w in pairs(getWindows()) do
if w.getClass()=="charsheet_skill" then
local label = w.label.getValue();
local type = w.skilltype.getValue();
if type >= SkillType.NoCheck then
type = type - SkillType.NoCheck;
end
if type~= SkillType.Custom then
w.skilltype.setValue(SkillType.Ignore);
end
if skilldata[label] then
if winlist[label] then
table.insert(winlist[label], w);
else
winlist[label] = { w };
end
end
end
end

and the warning when you click on a character sheet's skill tab this warning pops up


Script Warning: setValue: Recursive control event or call terminated (numbercontrol:bonus)
Script Warning: setValue: Recursive control event or call terminated (numbercontrol:bonus)
Script Warning: setValue: Recursive control event or call terminated (numbercontrol:bonus)
Script Warning: setValue: Recursive control event or call terminated (numbercontrol:bonus)
Script Warning: setValue: Recursive control event or call terminated (numbercontrol:bonus)
Script Warning: setValue: Recursive control event or call terminated (numbercontrol:bonus)
Script Warning: setValue: Recursive control event or call terminated (numbercontrol:bonus)

If these aren't show-stopper errors I should worry about then I'll just leave well enough alone. Is this happening because there is a ruleset version of charsheet_skilllist.lua as well as an extension version of the same script with the same name?

Trenloe
April 23rd, 2017, 05:48
Don't ignore errors as your script stops running at the point it encounters an error. Work out why getWindows is not valid on line 306 of scripts/charsheet_skilllist.lua

FlightlessScotsman
April 23rd, 2017, 05:50
Update:

For whatever reason I decided to delete everything but the following function in "charsheet_skilllist.lua" and save it in a new script called "charsheet_skilllist_mod.lua"


function getCategoryBonus(influence,characteristic)
if influence=="Primary" then
return math.ceil(characteristic/2);
end
return 0;
end

I edited the extension.xml file to only load the modified script and the MyScript.lua file and lo and behold no more errors and everything works as it should! So Hurray! No more worries, but it really makes me wonder why the same function inside the MyScript.lua just doesn't override the default calculation method as it seems it should.

Very weird, but hopefully this helps somebody and my pain is somebody else's gain

A huge thanks again Moon Wizard. Your help was invaluable.

FlightlessScotsman
April 23rd, 2017, 05:54
Don't ignore errors as your script stops running at the point it encounters an error. Work out why getWindows is not valid on line 306 of scripts/charsheet_skilllist.lua

It's a direct copy of the script from "charsheet_skilllist.lua" file inside the BRP ruleset .pak file, so it's nothing I wrote.

As I said at the top of the thread, I'm no programmer. I've dabbled a bit in javascript and python at points, but It's mostly just me knowing enough to be dangerous, I wouldn't even begin to know how debug and pull apart that error.