cscase
August 23rd, 2013, 06:26
Hey all,
I'm trying to put two numberfields on a character sheet and have their scripts reference one another, but having trouble getting things to work. I think this is a pretty straightforward example and I suspect one of you will be able to easily point out where I'm going wrong (knock on wood!).
The values are a rating (i.e. maximum value) and a pool (i.e. current value). So, what I'm trying to do in my script is just some basic sanity checking, like in this example, check to see if incrementing the pool value with scroll wheel would increase it above the max. But when I do things as I have it here, I get the error:
attempt to index field 'stats' (a nil value)
Here's how I'm trying to do it:
<numberfield name="SanPool" source=".stats.Sanity.pool">
... (various unrelated stuff here, position etc.) ...
<script>
function onWheel(notches)
if (getValue() + notches) <= window.stats.Sanity.rating.getValue()then
setValue(getValue() + notches);
else setValue(window.stats.Sanity.rating.getValue());
end
return true;
end
function onValueChanged()
if getValue() > window.stats.Sanity.rating.getValue() then
setValue(window.stats.Sanity.rating.getValue());
end
end
</script>
</numberfield>
And here's what the relevant portion of my database looks like:
<root version="2.9" release="1">
<charsheet>
<id-00001>
<stats>
<Sanity>
<pool type="number">13</pool>
<rating type="number">3</rating>
</Sanity>
</stats>
If I Debug.chat(getDatabaseNode()) from this control, the output says:
databasenode = { charsheet.id-00001.stats.Sanity.pool }
And if I say Debug.chat(window.getDatabaseNode()), it says:
databasenode = { charsheet.id-00001 }
If I do Debug.chat(window.stats.getDatabaseNode()) I get the error message.
If I try to use getParent() I just get an error. Maybe I'm calling that function incorrectly or it's somehow out of scope?
Tell me I'm doing something really silly. You have my thanks for reading this!
Scott
I'm trying to put two numberfields on a character sheet and have their scripts reference one another, but having trouble getting things to work. I think this is a pretty straightforward example and I suspect one of you will be able to easily point out where I'm going wrong (knock on wood!).
The values are a rating (i.e. maximum value) and a pool (i.e. current value). So, what I'm trying to do in my script is just some basic sanity checking, like in this example, check to see if incrementing the pool value with scroll wheel would increase it above the max. But when I do things as I have it here, I get the error:
attempt to index field 'stats' (a nil value)
Here's how I'm trying to do it:
<numberfield name="SanPool" source=".stats.Sanity.pool">
... (various unrelated stuff here, position etc.) ...
<script>
function onWheel(notches)
if (getValue() + notches) <= window.stats.Sanity.rating.getValue()then
setValue(getValue() + notches);
else setValue(window.stats.Sanity.rating.getValue());
end
return true;
end
function onValueChanged()
if getValue() > window.stats.Sanity.rating.getValue() then
setValue(window.stats.Sanity.rating.getValue());
end
end
</script>
</numberfield>
And here's what the relevant portion of my database looks like:
<root version="2.9" release="1">
<charsheet>
<id-00001>
<stats>
<Sanity>
<pool type="number">13</pool>
<rating type="number">3</rating>
</Sanity>
</stats>
If I Debug.chat(getDatabaseNode()) from this control, the output says:
databasenode = { charsheet.id-00001.stats.Sanity.pool }
And if I say Debug.chat(window.getDatabaseNode()), it says:
databasenode = { charsheet.id-00001 }
If I do Debug.chat(window.stats.getDatabaseNode()) I get the error message.
If I try to use getParent() I just get an error. Maybe I'm calling that function incorrectly or it's somehow out of scope?
Tell me I'm doing something really silly. You have my thanks for reading this!
Scott