Log in

View Full Version : Update database node types of modules works only with reload command?



JMessmer
December 29th, 2017, 11:38
Hello,

I am working on a new version of the dark eye ruleset. Because of some changes in the item area I added a script in the VersionManager which should update the datatype.

For some reason the code does not seem to run when starting a campaign with the module loaded. It only seems to run after typing /reload in the chat window.

Console Message:

[29.12.2017 11:18:10] Runtime Notice: s'scripts/manager_debug.lua, setLogLevel, Auswahl:' | s'0'
[29.12.2017 11:18:10] Runtime Notice: s'scripts/manager_version.lua, updateDatabase, minor: ' | #3
[29.12.2017 11:18:10] Runtime Notice: s'scripts/manager_version.lua, updateDatabase, major: ' | #6
[29.12.2017 11:18:21] Ruleset Error: windowcontrol: Database type mismatch for control (nonidentified) in windowclass (item_description)
[29.12.2017 11:18:21] Ruleset Error: windowcontrol: Database type mismatch for control (nonidentified_player) in windowclass (item_description)

Code fragment of VersionManager:


function onInit()
DebugM.printLogMessage("scripts/manager_version.lua, onInit");
if User.isHost() then
updateDatabase(DB.findNode("."));
end

OOBManager.registerOOBMsgHandler("OOB_lCA", onOOBlCANachricht); --Aufruf bei lokaler Charakterauswahl
DebugM.printLogMessage("scripts/manager_version.lua, onInit, Ende");
end

function updateDatabase(nodeRoot)
DebugM.printLogMessage("scripts/manager_version.lua, updateDatabase");
if not nodeRoot then
return;
end

local major, minor = nodeRoot.getRulesetVersion();
Debug.console("scripts/manager_version.lua, updateDatabase, minor: ", minor);
Debug.console("scripts/manager_version.lua, updateDatabase, major: ", major);

-- Florindel, To-Do: entfernen nachdem Tests abgeschlossen sind
updateItems();
[...]
end

function updateItems()
DebugM.printLogMessage("scripts/manager_version.lua, updateItems");
-- Florindel, läuft nur bei jedem zweiten Mal durch die Module??
local nodeItem = DB.findNode("item");
Debug.console("versionmanager, updateItems, nodeItem: ", nodeItem);
if nodeItem then
for _, v in pairs(DB.getChildrenGlobal(nodeItem)) do
Debug.console("versionmanager, updateItems, v: ", v);
local nodeNonId = v.getChild("nonidentified");
Debug.console("versionmanager, updateItems, nodeNonId: ", nodeNonId);
if nodeNonId and nodeNonId.getType() ~= "formattedtext" then
local sText = nodeNonId.getValue();
nodeNonId.delete();
DB.setValue( v, "nonidentified", "formattedtext", sText );
end
[...]
end
end
end


After entering /reload the console contains this:


[29.12.2017 11:24:25] Runtime Notice: s'scripts/manager_version.lua, updateDatabase, minor: ' | #3
[29.12.2017 11:24:25] Runtime Notice: s'scripts/manager_version.lua, updateDatabase, major: ' | #6
[29.12.2017 11:24:25] Runtime Notice: s'versionmanager, updateItems, nodeItem: ' | databasenode = { item }
[29.12.2017 11:24:25] Runtime Notice: s'versionmanager, updateItems, v: ' | databasenode = { item.id-00001@DSA Atlas }
[29.12.2017 11:24:25] Runtime Notice: s'versionmanager, updateItems, nodeNonId: ' | databasenode = { item.id-00001.nonidentified@DSA Atlas }
[29.12.2017 11:24:25] Runtime Notice: s'versionmanager, updateItems, v: ' | databasenode = { item.id-00002@DSA Atlas }
[29.12.2017 11:24:25] Runtime Notice: s'versionmanager, updateItems, nodeNonId: ' | databasenode = { item.id-00002.nonidentified@DSA Atlas }


I expected that the code would run even when loading the campaign for the first time.

Regards,
Jens

JMessmer
December 29th, 2017, 12:40
Already found a solution:
1. I removed


local nodeItem = DB.findNode("item");
Debug.console("versionmanager, updateItems, nodeItem: ", nodeItem);
if nodeItem then
and changed
for _, v in pairs(DB.getChildrenGlobal(nodeItem)) do
into
for _, v in pairs(DB.getChildrenGlobal("item")) do

2. in module_selectionentry.lua I added VersionManager.updateItems(); to the function activate() so that the code is also triggered when activating a module during play.

Are there any suggestions to improve it even further?

Moon Wizard
January 2nd, 2018, 08:07
I would use the examples in the 3.5E ruleset version manager code, since there have been many database migrations in that ruleset over the years.

Regards,
JPG

JMessmer
January 3rd, 2018, 11:33
Thanks a lot, Jpg. I will take a look at it.