PDA

View Full Version : Return order of getChildren as per XML order



MadBeardMan
October 6th, 2019, 13:03
Afternoon Folks,

I've got a node which stores the results of the dice rolls. Works lovely:


<savedroll>
<id-00004>
<result type="number">6</result>
</id-00004>
<id-00005>
<result type="number">10</result>
</id-00005>
<id-00006>
<result type="number">3</result>
</id-00006>
</savedroll>

However when I do a DB call and get the children, they come in a random order, last time it was:


Runtime Notice: s'v' | databasenode = { charsheet.id-00005.savedroll.id-00006 }
Runtime Notice: s'v' | databasenode = { charsheet.id-00005.savedroll.id-00005 }
Runtime Notice: s'v' | databasenode = { charsheet.id-00005.savedroll.id-00004 }

Next time it was 8,9,7

Any thoughts?

Cheers
MBM

Ikael
October 6th, 2019, 21:50
That is correct. DB.getChildren does not return in order where they are presented in XML, instead they are identified by their node name (string type) in table and when you use pairs to iterate them through they seem to come out in "random" order. In SavageWorlds I had need to get them in asc order so I have implemented getChildrenSorted function t achieve that.


Afternoon Folks,

I've got a node which stores the results of the dice rolls. Works lovely:



However when I do a DB call and get the children, they come in a random order, last time it was:



Next time it was 8,9,7

Any thoughts?

Cheers
MBM

MadBeardMan
October 6th, 2019, 22:42
That is correct. DB.getChildren does not return in order where they are presented in XML, instead they are identified by their node name (string type) in table and when you use pairs to iterate them through they seem to come out in "random" order. In SavageWorlds I had need to get them in asc order so I have implemented getChildrenSorted function t achieve that.

It's ok I fixed it myself.

I now have the 'dice' number stored along with the result, and it sets the 'Dice..i' with that value.

Cheers!
MBM