PDA

View Full Version : Not registering multple tags



ianmward
March 29th, 2016, 08:28
Hi,

I have a problem with a ruleset layered on CoreRPG where I define a custom tag and FG is only remembering the last instance of the tag instead of creating an array of values.
I am probably doing something wrong, please tell me what.

This is a fragment of my XML:


<basicnumber name="strength" source="abilities.strength">
<anchored to="abilityframe" position="insidetopleft" offset="60,20" width="30" height="25"/>
<anchored width="30" height="25" />
<script>
function onInit()
onValueChanged();
end
function onValueChanged()
Debug.console("onValueChanged: ", derivedcontrol,getDatabaseNode(), self);
for _,v in pairs(derivedcontrol) do
window[v].update(getDatabaseNode());
end
end
</script>
<derivedcontrol>strength_half</derivedcontrol>
<derivedcontrol>strength_fifth</derivedcontrol>
</basicnumber>
What I see in the Console is:


Runtime Notice: s'onValueChanged: ' | { #1 = s'strength_fifth' } | databasenode = { charsheet.id-00001.abilities.strength } | numbercontrol = { value = #85, x,y,w,h = 70,20,30,25 }


So you see that the derivedcontrol tag is being seen but only the last instance is remembered.

Is there a way to make it create an array of values or do I need to think of a better way to do this?

Cheers

Ian

ianmward
March 29th, 2016, 08:42
Okay, so I looked for some similar code that I thought worked and changed mine to be similar:


<basicnumber name="strength" source="abilities.strength">
<anchored to="abilityframe" position="insidetopleft" offset="60,20" width="30" height="25"/>
<anchored width="30" height="25" />
<script>
function onInit()
onValueChanged();
end
function onValueChanged()
if derivedcontrols and derivedcontrols[1] and derivedcontrols[1].control then
Debug.console("onValueChanged: ", derivedcontrols,getDatabaseNode(), self);
for _,v in pairs(derivedcontrols[1].control) do
window[v].update(getDatabaseNode());
end
end
end
</script>
<derivedcontrols>
<control>strength_half</control>
<control>strength_fifth</control>
</derivedcontrols>
</basicnumber>
This works but I am curious why...

Cheers

Ian

Moon Wizard
March 29th, 2016, 21:18
It works in a control I tried, so my guess is that it might be an anomaly in the way that templates are merged in some cases. If it's a showstopper, let me know and I can do a full trace.

Regards,
JPG

ianmward
March 29th, 2016, 22:43
Thanks Moon Wizard, it's ok.
As I said, I got it working with the second post. I was just curious...