PDA

View Full Version : Creating a child node with autogenerated name



darrenan
June 2nd, 2021, 20:43
Both DB.createChild and databasenode.createChild have the following documented for the 'name' parameter:


name (string) [optional]
A relative node identifier specifying the child node to find. If this parameter is omitted, a new unique node name will be generated.

How do you omit a parameter? Passing in nil or "" to these functions causes a script error. Omitting the parameter entirely, for example myNode.createChild("string") or DB.createChild(myNode, "string"), creates a node named string instead of autogenerating a name. Is this documentation incorrect?

In general, how do you directly create a typed node with an autogenerated name?

Trenloe
June 2nd, 2021, 20:49
<dbnode>.createChild() and DB.createChild(<dbnode>) will create a new intermediary node with the usual auto generated id-XXXXX name. I don't think you can create an auto generated node name and specify a type.

darrenan
June 2nd, 2021, 20:54
Ok, seems like I can get around it by just adding one more level of node.

Trenloe
June 2nd, 2021, 21:38
The usual naming convention is that intermediary nodes will have id-XXXXX or a name (but no type) - the vast majority will be id-XXXXX, you'll see that everywhere in FG db.xml (campaign and modules). I'd stick with that naming if you're creating a child that will have multiple entries under it.

If it's a child with just one entry, then use a meaningful unique name.

I'm not sure what you're trying to do, so can't make definite recommendations. So I don't know if adding one more level of code is the way to go or not.

Moon Wizard
June 2nd, 2021, 22:38
If you are creating a value node; then you should probably be using a unique name anyway.
The auto-generated child names are more for branch nodes that represent whole records.

Regards,
JPG