PDA

View Full Version : Using <numberlinked' to access field values in different part of the character sheet



MadBeardMan
January 2nd, 2019, 15:19
Greetings All,

Can't seem to get my code working.

I've got a Psionics Tab which has a field which links back to an attribute, very simple.

Yet, as this attribute is 3 parent up I can't seem to access it, I'm a bit stumped.


<number_linked name="characteristicDM">
<anchored width="30" height="20">
<top offset="2" />
<right parent="rightanchor" anchor="left" relation="relative" offset="-15" />
</anchored>
<source><name>....attributes.psi_mod</name></source>
<tabtarget prev="characteristic" next="level" />
<script>
function onInit()

onSourceUpdate()
end
function onSourceUpdate(source)
print ('Source Update')
local nValue = calculateSources();
print (nValue)

if getValue() ~= nValue then
setValue(nValue);
end
end
</script>
</number_linked>

So how do I get it to look 'elsewhere', it must be something simple, I just can't see it today (probably the 4 hours and 30 minutes sleep I got last night).

Cheers,
Col

Trenloe
January 2nd, 2019, 15:32
The number_linked control is primarily used to link a number of data sources together into one display value - e.g. totals for a specific area of interest.

If all you're wanting to do is access/display a number from elsewhere in the PC database then use the normal numberfield control (or a relevant template based on this) and define it as something like this:

<numberfield name="characteristicDM" source="....attributes.psi_mod">

MadBeardMan
January 2nd, 2019, 15:34
The number_linked control is primarily used to link a number of data sources together into one display value - e.g. totals for a specific area of interest.

If all you're wanting to do is access/display a number from elsewhere in the PC database then use the normal numberfield control (or a relevant template based on this) and define it as something like this:

<numberfield name="characteristicDM" source="....attributes.psi_mod">

Hi Chap,

I tried that, it writes back to the original field which I don't want, but if it's the best way I'll read only the field.

Tired brain today!

Cheers
Col

Trenloe
January 2nd, 2019, 15:47
Hi Chap,

I tried that, it writes back to the original field which I don't want, but if it's the best way I'll read only the field.

Tired brain today!

Cheers
Col
Make the field <readonly />, so it just displays the original and doesn't allow any modifications. Unless I'm completely missing what you're trying to do.

And, although the number_linked template is overkill, the reason it probably wasn't working for you, is that you don't have an operator "op" property for the source in your code in post #1.

MadBeardMan
January 2nd, 2019, 15:57
The number_linked control is primarily used to link a number of data sources together into one display value - e.g. totals for a specific area of interest.

If all you're wanting to do is access/display a number from elsewhere in the PC database then use the normal numberfield control (or a relevant template based on this) and define it as something like this:

<numberfield name="characteristicDM" source="....attributes.psi_mod">

Now I remember why I stopped using that, the 'value' is never saved in the DB.


<id-00003>
<characteristicDM type="number">0</characteristicDM>
<level type="number">1</level>
<locked type="number">1</locked>
<name type="string">Clairvoyance</name>
<noedit type="number">1</noedit>
<text type="formattedtext">
<p></p>
</text>
<total type="number">1</total>
</id-00003>

Even though the field shows '1' which is correct, the field characteristicDM is at 0.

As there's a total that calculates that field plus your skill level.

Thoughts?

Cheers

Trenloe
January 2nd, 2019, 16:03
I'm completely confused as to what you're trying to do.

MadBeardMan
January 2nd, 2019, 16:06
I'm completely confused as to what you're trying to do.

Ok.

Very simple.

On the PSI tab you have a Name, a DM (the modifier from your attribute) and Level (your Skill Level), these two totalled are you Bonus to your 2D6 dice roll.

So every PSI ability uses your PSI Mod (which is the DM), so no need for the Attribute Cycler that I use for normal skills.

So what I need is for the record to have the PSI mod saved as 'CharacteristicDM' so the calculation on the Total is all correct.

Trenloe
January 2nd, 2019, 16:14
So what I need is for the record to have the PSI mod saved as 'CharacteristicDM' so the calculation on the Total is all correct.
Why can't you go direct to the original Characteristic to get the value? Why do you need the exact same value in another database field? Or are you doing the calculations on the data in the GUI controls rather than on the database values?

I'd recommend you do all calculations based off the source (master, if you like) database fields. Display a read only control if you want to display the original modifier, but your total should be calculated off the original master data.

In this instance, I would use the number_linked template to calculate the skill total (because that is primarily what that control template is used for - linking a number of fields together to give a total based off the <op> entries for each source) - using <source> entries for the attribute modifier and the skill level. Something like:

<source><name>....attributes.psi_mod</name><op>+</op></source>
<source><name>.skill_level</name><op>+</op></source>

MadBeardMan
January 2nd, 2019, 17:15
Why can't you go direct to the original Characteristic to get the value? Why do you need the exact same value in another database field? Or are you doing the calculations on the data in the GUI controls rather than on the database values?

I'd recommend you do all calculations based off the source (master, if you like) database fields. Display a read only control if you want to display the original modifier, but your total should be calculated off the original master data.

In this instance, I would use the number_linked template to calculate the skill total (because that is primarily what that control template is used for - linking a number of fields together to give a total based off the <op> entries for each source) - using <source> entries for the attribute modifier and the skill level. Something like:

<source><name>....attributes.psi_mod</name><op>+</op></source>
<source><name>.skill_level</name><op>+</op></source>

Hi Chap,

Works a treat, here's the code in the XML view:


<number_charpsitotal name="total">
<anchored width="30" height="20">
<top offset="2" />
<right parent="rightanchor" anchor="left" relation="relative" offset="-5" />
</anchored>
</number_charpsitotal>

And this is the code for that template:


<template name="number_charpsitotal">
<number_linked>
<frame name="fieldlight" offset="5,5,5,5" />
<source><name>level</name><op>+</op></source>
<source><name>...attributes.psi_mod</name><op>+</op></source>
<script>
function action(draginfo)
local nodeWin = window.getDatabaseNode();

if nodeWin then

local nTotal = getValue();
local nodeSkill = window.name.getValue();
local nodeChar = nodeWin.getChild("...");
local rActor = ActorManager.getActor("pc", nodeChar);

ActionSkill.performRoll(draginfo, rActor, nodeSkill, nTotal);

end

return true;
end

function onDragStart(button, x, y, draginfo)
return action(draginfo);
end

function onDoubleClick(x,y)
return action();
end
</script>
</number_linked>
</template>


It needs updating to work properly but at least it's calculating. One odd thing though, if I name the template 'number_charpsitalenttotal' then it doesn't work. Odd.

Cheers!