PDA

View Full Version : basicnumber source and inline Lua script assignation call to obtain value



IchiSkaar
January 3rd, 2016, 03:21
Hi everyone.

Happy new year to all.

I tried to Google and search within different existing RuleSet before asking here: you will understand I was unable to find an answer.

I defined a basicnumber within a subwindow with source='foo.boo.roo". On the parent window, I have another basicnumber were I want to use (for now) an inline Lua script to get a derived value.

I was able to update my value


local minValue = 20;
local e = 1;
local maxValue = minValue + e * 8;
setValue(maxValue);


I'm looking to replace the 'local e = 1;' line with 'local e = foo.boo.roo.getValue();' but this return index global 'foo' (a nil value).

What would be the proper assignation call?

Thanks for the assistance. Guess I just require some sleep but since I have been working on this the past 8 hours I felt it would be best to seek assistance.

damned
January 3rd, 2016, 04:36
if you look in the db.xml does foo.boo.roo have a value? is it a number or a string?

Trenloe
January 3rd, 2016, 06:39
You can't just use database notation directly. You need to use the notation to get a database node and then get the value of that database node.

You could use DB.findNode("foo.boo.roo").getValue();

Info on DB.findNode here: https://www.fantasygrounds.com/refdoc/DB.xcp#findNode which returns a <databasenode> and then info on <databasenode).getValue here: https://www.fantasygrounds.com/refdoc/databasenode.xcp#getValue

IchiSkaar
January 3rd, 2016, 17:47
Thanks all. I will give another try, I was not using the good function against DB API in my test. I will keep you updated of my progress.

Damned: It should be a number but your comment made me realized I will have to test using a new PC and see if it cause issue.

IchiSkaar
January 3rd, 2016, 19:54
I must be missing something: frustration just keep pilling up. Does defining a source on a numberfield automatically create a node in the DB interface? It seems not per my test but looking at the CoreRPG and 5E ruleset it looks like it.

On charsheet window:


<script>
function onInit()
...
Debug.console(DB.findNode("characteristics.physic.endurance"));
Debug.console(DB.findNode("characteristics_physic_endurance"));

Runtime Notice: nil
Runtime Notice: nil


On charsheet_main window:


...
<basicnumber name="characteristics_physic_endurance" source="characteristics.physic.endurance">
<min>1</min><max>6</max><default>1</default>
...
</basicnumber>


In [RuleSet].xml file:


<character portrait="">
<characteristics>...
<physic>
...
<endurance type="number">4</endurance>


If full code is required I would prefer to communicate in private.

Thanks for any type of hints.

Trenloe
January 3rd, 2016, 21:28
When is onInit being called? If this is during window/control creation for the first time then the underlying database nodes won't have been created at that point.

Let the window and controls be created. Then type /save in the chat window and open up the campaign db.xml file - see if the data is being stored there. If not, then you are having issues with the data being created in the database, if the data is there then move your code out of the onInit function to a place where the control (and therefore the underlying data) has been fully created.

IchiSkaar
January 4th, 2016, 03:03
Thanks Trenloe.

It did provided me a bit more information on my error.

This did help me a figure the missing pieces: https://www.fantasygrounds.com/forums/archive/index.php/t-14761.html



local endurance = window.getDatabaseNode().getChild("characteristics.physic.endurence").getValue();
local maxValue = minValue + endurance * 8;
window.getDatabaseNode().getChild("characteristics.derive.lifePoint.maximum").setValue(maxValue);


This fixed my context issue that I found related to "charsheet.id-0000#.characteristics..." full path.

Also found the window.getDatabaseNode() may not be equal to getDatabaseNode().

Now... Just require to find how I can define utility API like CharManager of the CoreRPG.

Thanks a lot for your time.

Trenloe
January 4th, 2016, 03:19
This fixed my context issue that I found related to "charsheet.id-0000#.characteristics..." full path.
Ah, right - it wasn't clear exactly where your data was in the database. Glad you sorted it out.

More info on database structure here: https://www.fantasygrounds.com/modguide/database.xcp


Also found the window.getDatabaseNode() may not be equal to getDatabaseNode().
Just using getDatabaseNode() without the specific element will make the call to the element that currently has scope - which depends on where the script is running. If the script is running within a control then it will be running with scope against that control and not the window. getDatabaseNode() against a control will only be valid if that control inherits databasecontrol (https://www.fantasygrounds.com/refdoc/databasecontrol.xcp), which numberfield does.


Now... Just require to find how I can define utility API like CharManager of the CoreRPG.

See the "Script packages" section here: https://www.fantasygrounds.com/modguide/scripting.xcp