PDA

View Full Version : Bug in copyNode-function or whats wrong with the code?



lule
December 24th, 2013, 11:41
Hello FG-Users,

I have some troubles with a part of the code in the VersionManager.

Here is the code:


local talentknoten = DB.findNode(charknoten..".skilllist");
Debug.console("charknoten", charknoten);
Debug.console("talentknoten", talentknoten);
if talentknoten then
for v,k in pairs(talentknoten.getChildren()) do
--[[Lule: v = name of the node, k = node itself]]
Debug.console("v", v);
Debug.console("k", k);
if v == "kampf" then
for a,s in pairs(k.getChildren()) do
Debug.console("a", a);
Debug.console("s", s);

pruefknoten = s.getChild("at");
if pruefknoten then
DB.copyNode(charknoten .. ".skilllist." .. v .. "." .. a .. ".at", charknoten .. ".skilllist." .. v .. "." .. a .. ".attackeTalentwert");
pruefknoten.delete();
end

And here the Log of the console:


Runtime Notice: s'charknoten' | s'charsheet.id-00001'
Runtime Notice: s'talentknoten' | databasenode = { charsheet.id-00001.skilllist }
Runtime Notice: s'v' | s'kampf'
Runtime Notice: s'k' | databasenode = { charsheet.id-00001.skilllist.kampf }
Runtime Notice: s'a' | s'id-00002'
Runtime Notice: s's' | databasenode = { charsheet.id-00001.skilllist.kampf.id-00002 }
Script Error: [string "scripts/manager_version.lua"]:811: copyNode: Destination node can not be the same as or a child of the source node

They are not the same node, as they end differently ".at" vs. ".attackeTalentwert" and they are not a child of each other. Or am I logically wrong here?

Is something wrong in the code or is there a bug in the copyNode-function?

Regards,
Lule

Trenloe
December 24th, 2013, 17:55
Have you tried using a different databasenode variable to charknoten for the target node? It may be that the error handler is seeing the same databasenode variable and raising the error on that, not off the final target node. This would still be a bug, but using a different databasenode may be a work around (just use targetnode = charknoten for the new target node)??

Moon Wizard
December 24th, 2013, 21:56
Just guessing since I am traveling right now. I think the "parent" check might be a simple substring check, which would technically be a bug.

Regards,
JPG

lule
January 10th, 2014, 12:32
Thanks for the reply.

I did some testing (version 3.0.1 and 3.0.2).

The problem only occurs when the first letters of the destnode name (last node) are identical with the whole sourcenode name (last node). Examples:

sourcenode name -> destnode name

problems:
at -> attack
na -> name
name -> nameChar
label -> labelcycler

no problems:
at -> another
na -> notavailable
name -> noname
label -> leftlabel
name -> namable


1. With FG version 2.9.4 there are no errors with the code. Tested via Dev-version.
2. I think, but this is not tested, there is no error, when the destnode is different from the sourcenode before the last node.


I hope this is helpful.

Regards,
Lule

Moon Wizard
January 10th, 2014, 21:28
Just pushed a new update to the Test version (v3.0.2) that addresses this issue.

JPG

lule
January 11th, 2014, 09:19
Thanks a lot JPG! With version 3.0.2 there are no more errors.