PDA

View Full Version : Accessing node attributes in Lua



Tommycore
March 30th, 2020, 15:59
Hi folks.

The dev guide is saying "Attributes are not accessible in this manner" (1). Looking if there is another way only brought up age old threads, and examining CoreRPG sourcecode didn't yield anything useful either, so I wanted to ask what the current status on that is: Is there a way to access node attributes in Lua, and if so, how would one go about it?


Cheers!
___
1 https://www.fantasygrounds.com/wiki/index.php/Developer_Guide_-_Rulesets_-_Scripting#Accessing_XML_Parameters_from_Scripts

superteddy57
March 30th, 2020, 16:17
To be more helpful, what are you attempting to try and access?

Tommycore
March 30th, 2020, 17:13
Custom attributes. I know I can interact with a lot of the built in stuff like anchoring for controls etc. via getter and setter. But being able to leave multiple custom parameters for my scripts in a single self closing tag, instead of bloating up my node tree would be nice.

Turning this:

<genericcontrol name="foo">
<param1>These</param>
<param2>Are</param>
<param3>Parameters</param>
</genericcontrol>
into this:

<genericcontrol name="" param1="These" param2="Are" param3="Parameters" />

superteddy57
March 30th, 2020, 17:44
Depending on the type of element you are using to store data within the code, they may save to the database. I would suggest checking over the reference document for the different element types and how to access them. If the data does get stored to the database, you can use lua to access the node in question. Here is a link for a break down of the code that may assist.

https://www.fantasygrounds.com/refdoc/databasenode.xcp

Moon Wizard
March 30th, 2020, 23:05
Attributes are not converted into Lua variables; only tags are. So, the example in post 3 means that param1, param2 and param3 would not be available as variables within the Lua script.

Regards,
JPG

Tommycore
March 30th, 2020, 23:12
Thank you both =)