PDA

View Full Version : 5E - Issue adding a 2nd Background to the character sheet.



ColinBuckler
December 31st, 2021, 23:05
Using the 5E ruleset I have managed to add a 2nd Background to the character sheet and can type into the text box. This is to allow for a Background as well as an Education Background.

The problem is with the drag/drop of backgrounds - only the first box is ever populated.

I can see the problem with code being:


<windowclass name="charsheet_main">
<script>
function onDrop(x, y, draginfo)
if draginfo.isType("shortcut") then
local sClass, sRecord = draginfo.getShortcutData();

if StringManager.contains({"reference_class", "reference_race", "reference_subrace", "reference_background"}, sClass) then
CharManager.addInfoDB(getDatabaseNode(), sClass, sRecord);
return true;
end
end
end

As it always stores the background in the "background" field.

What I would like the code to do is if it is a background:

(1) To check to see if the background field has a value - if it doesnt store the background in here as normal.
(2) If the background field has a value in it - move the contents of background field and replace whatever is in background2. Then add the background as per (1).

Not 100% sure on how to get the contents of the background field, check it and then to save the new field. I am sure its only about 3 or 4 lines of code.

Any tips on the commands to accomplish this?

Moon Wizard
January 1st, 2022, 02:26
All of the code for the character manager assumes a single background text and link field; which is what is populated by the scripts on a drop action.

If you are adding a second background field; then you'll need to add a second background link; and intercept the drop on the second background text/link fields to handle yourself, instead of allowing the drop to fall through to the main character sheet handler. (And, when doing this, dropping anywhere but the second field will use the default handling.)

Regards,
JPG

ColinBuckler
January 1st, 2022, 15:42
Managed to get it working by adding:


if StringManager.contains({"reference_background"}, sClass) then
backeducate.setValue( background.getValue());
backeducatelink.setValue( backgroundlink.getValue());
end


With the complete bit of code looking like:


<windowclass name="charsheet_main" merge="join">
<script>
function onDrop(x, y, draginfo)
if draginfo.isType("shortcut") then
local sClass, sRecord = draginfo.getShortcutData();

if StringManager.contains({"reference_background"}, sClass) then
backeducate.setValue( background.getValue());
backeducatelink.setValue( backgroundlink.getValue());
end

if StringManager.contains({"reference_class", "reference_race", "reference_subrace", "reference_background"}, sClass) then
CharManager.addInfoDB(getDatabaseNode(), sClass, sRecord);
return true;
end
end
end

function onHealthChanged()
local sColor = ActorManager5E.getPCSheetWoundColor(getDatabaseNod e());
wounds.setColor(sColor);
end
</script>

damned
January 1st, 2022, 23:27
Well done.