Starfinder Playlist
  1. #1

    Bug with DB.setValue using 3 params and dbnode instead of path

    I was just developing a registry for managing Crossreferences of dbnodes within a dedicated manager when I stumbed upon this bug that using
    DB.setValue(targetNode, "number", 20)
    does not work while
    DB.setValue(DB.getPath(targetNode), "number", 20)
    does.
    According to the API ref:
    function setValue(sourcenode, [subpath], type, value)
    sourcenode (string (or databasenode))
    A data node identifier path (or a databasenode object) representing the target node
    both options should be possible!

    Example:
    Code:
    _tHandlerRegistry = {};
    function onClose()
    	local sFuncName = "onClose";
    	DebugManager.printLogMessage2(sScriptName, sFuncName);
    	if _tHandlerRegistry then
    		for k, v in pairs(_tHandlerRegistry) do
    			DB.removeHandler(DB.getPath(k), v["action"], handleUpdate);
    		end
    	end
    	DebugManager.printLogMessage2(sScriptName, sFuncName, "Ende");
    end
    function addLinkHandler(originalNode, targetNode, sAction, func)
    	local sFuncName = "addLinkHandler";
    	DebugManager.printLogMessage2(sScriptName, sFuncName);
    	if not originalNode or not targetNode then
    		DebugManager.printLogMessage2(sScriptName, sFuncName, "Ende mit nil");
    		return;
    	end
    	if originalNode.getType() ~= targetNode.getType() then
    		DebugManager.printLogMessage2(sScriptName, sFuncName, "Ende mit inkompatiblen Datentypen");
    		return;
    	end
    	_tHandlerRegistry[originalNode] = {target = targetNode, action = sAction, funcRef = func};
    	DB.addHandler(DB.getPath(originalNode), sAction, handleUpdate);
    	DebugManager.printLogMessage2(sScriptName, sFuncName, "Ende");
    end
    function handleUpdate(source)
    	local sFuncName = "handleUpdate";
    	DebugManager.printLogMessage2(sScriptName, sFuncName);
    	DebugManager.printDebugMessage2(sScriptName, sFuncName, "source: ", source);
    	registryEntry = _tHandlerRegistry[source];
    	DebugManager.printDebugMessage2(sScriptName, sFuncName, "registryEntry: ", registryEntry);
    	registryEntry["funcRef"](source, registryEntry["target"]);
    	DebugManager.printLogMessage2(sScriptName, sFuncName, "Ende");
    end
    function updateLanguageList(source, target)
    	local sFuncName = "updateLanguageList";
    	DebugManager.printLogMessage2(sScriptName, sFuncName);
    	DebugManager.printDebugMessage2(sScriptName, sFuncName, "source: ", source);
    	DebugManager.printDebugMessage2(sScriptName, sFuncName, "target: ", target);
    	DebugManager.printDebugMessage2(sScriptName, sFuncName, "source.getType(): ", source.getType());
    	DebugManager.printDebugMessage2(sScriptName, sFuncName, "target.getType(): ", target.getType());
    	local sTargetDataType = target.getType();
    	local sourceValue = DB.getValue(source);
    	DebugManager.printDebugMessage2(sScriptName, sFuncName, "sTargetDataType: ", sTargetDataType);
    	DebugManager.printDebugMessage2(sScriptName, sFuncName, "sourceValue: ", sourceValue);
    	DB.setValue(target.getParent(), "wert", "number", 20);
    	DB.setValue(DB.getPath(target), sTargetDataType, sourceValue); -- this one works!
    	DB.setValue(target, sTargetDataType, sourceValue); -- this one does not!!
    	DebugManager.printLogMessage2(sScriptName, sFuncName, "Ende");
    end
    
    ...
    function testfunction()
        self.addLinkHandler(languageTalentNode.getChild("talentwert"), langListNode.getChild(LanguageManagerDSA.CAMPAIGN_LANGUAGE_LIST_VALUE), "onUpdate", updateLanguageList)
    end
    Debugging output:
    [3/20/2024 2:05:48 PM] s'gm | scripts/manager_talent_DSA.lua, handleUpdate'
    [3/20/2024 2:05:48 PM] s'gm | scripts/manager_talent_DSA.lua, handleUpdate, source: ' | databasenode = { charsheet.id-00003.skilllist.sprechen.id-00001.talentwert }
    [3/20/2024 2:05:48 PM] s'gm | scripts/manager_talent_DSA.lua, handleUpdate, registryEntry: ' | { s'target' = databasenode = { charsheet.id-00003.languagelist.id-00003.wert }, s'action' = s'onUpdate', s'funcRef' = fn }
    [3/20/2024 2:05:48 PM] s'gm | scripts/manager_talent_DSA.lua, updateLanguageList'
    [3/20/2024 2:05:48 PM] s'gm | scripts/manager_talent_DSA.lua, updateLanguageList, source: ' | databasenode = { charsheet.id-00003.skilllist.sprechen.id-00001.talentwert }
    [3/20/2024 2:05:48 PM] s'gm | scripts/manager_talent_DSA.lua, updateLanguageList, target: ' | databasenode = { charsheet.id-00003.languagelist.id-00003.wert }
    [3/20/2024 2:05:48 PM] s'gm | scripts/manager_talent_DSA.lua, updateLanguageList, source.getType(): ' | s'number'
    [3/20/2024 2:05:48 PM] s'gm | scripts/manager_talent_DSA.lua, updateLanguageList, target.getType(): ' | s'number'
    [3/20/2024 2:05:48 PM] s'gm | scripts/manager_talent_DSA.lua, updateLanguageList, sTargetDataType: ' | s'number'
    [3/20/2024 2:05:48 PM] s'gm | scripts/manager_talent_DSA.lua, updateLanguageList, sourceValue: ' | #10
    [3/20/2024 2:05:48 PM] [ERROR] Handler error: [string "DSA_DZ_4.1:scripts/manager_talent_DSA.lua"]:305: setValue: Invalid data type parameter

  2. #2
    It's an either/or scenario.

    If you specify a "databasenode" object as the first parameter, then the format is:
    DB.setValue(node (databasenode), child (string), type (string), value)
    NOTE: "." can be used as the second parameter to self-reference the databasenode.

    If you specify a "string" object as the first parameter, then the format is:
    DB.setValue(dbpath (string), type (string), value)

    Regards,
    JPG

  3. #3
    I would kindly ask you to update the API reference then, please. I am working on rulesets in my free time, and it is really annoying to spend hours on functionality that should be working according to the documentation.

    It would have been very helpful to know that the expected param-types for the functions are like this:
    DB.setValue(databasenode, string, string, ANY)
    DB.setValue(string, string, ANY)
    And I was already wondering how you manage the optional parameter with the same signature - at least this is clear now.

  4. #4
    I've updated the DB.getValue/setValue API documentation to split the two different parameter sets available to each.

    Regards,
    JPG

  5. #5
    Thanks Jpg, I really appreciate this.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
FG Spreadshirt Swag

Log in

Log in