View Full Version : DB.getValue() parameter double-check
Varsuuk
March 30th, 2019, 19:05
[RESOLVED]
I see in the 5E addCharRef code the line:
for _,v in pairs(aCharClassNodes) do
local _,sExistingClassPath = DB.getValue(v, "shortcut", "", "");
I am not sure what the 2nd "" stands for. On the API page it only mentions 3 arguments.
https://www.fantasygrounds.com/refdoc/DB.xcp#getValue
I understand extras in Lua are "ignored", but checking in case it is because of an enhancement to the API that didn't make the web page.
celestian
March 30th, 2019, 20:45
I see in the 5E addCharRef code the line:
for _,v in pairs(aCharClassNodes) do
local _,sExistingClassPath = DB.getValue(v, "shortcut", "", "");
I am not sure what the 2nd "" stands for. On the API page it only mentions 3 arguments.
https://www.fantasygrounds.com/refdoc/DB.xcp#getValue
I understand extras in Lua are "ignored", but checking in case it is because of an enhancement to the API that didn't make the web page.
Shortcut contains a "class" and "record" values.
local sClass, sRecord = DB.getValue(node, "shortcut", "", "");
DB.setValue(nodeClass, "shortcut", "windowreference", sClass, sRecord);
sClass = "item" or "charsheet" or "npc".
sRecord="item.id-00001" or "charsheet.id-00312"
Varsuuk
March 31st, 2019, 03:35
I GET it now. I read the "function getValue( sourcenode, [subpath], [default] )" and would have expected: "function getValue( sourcenode, [subpath], [default, ...] )" or some symbology to indicate multiple defaults.
I knew it returned two values for this method (I print these generally to find out) but it never occurred to me that the it was for multiple "defaults" to return - which of course makes sense :)
The key, of course, that I missed being the "(s)" ;)
default (...) [optional] The value(s) to be returned if getValue fails. (node does not exist; or non-value node)
Thanks
celestian
March 31st, 2019, 08:36
I GET it now. I read the "function getValue( sourcenode, [subpath], [default] )" and would have expected: "function getValue( sourcenode, [subpath], [default, ...] )" or some symbology to indicate multiple defaults.
I knew it returned two values for this method (I print these generally to find out) but it never occurred to me that the it was for multiple "defaults" to return - which of course makes sense :)
The key, of course, that I missed being the "(s)" ;)
default (...) [optional] The value(s) to be returned if getValue fails. (node does not exist; or non-value node)
Thanks
Ah, yeah, the bits on the end set it's defaults if it's nil. That's why I almost ALWAYS use DB.getValue(node,"something","default") and never node.name.getValue(). I almost always want something back even if it's my default.
Powered by vBulletin® Version 4.2.1 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.