PDA

View Full Version : Question about windowlist functions.



drahkar
May 18th, 2011, 10:33
So, I'm reading over the windowlist database nodes and I've found that whenever a new entry is made in the list, the base node for the windowlist gets the attribute 'idcounter' added to it with a value of the total number of entries that have been created in the list since the node was created. For example. If your windowlist had a base Database Node of skills and you had over the life of the node created 20 entries, the base Database Node would look like <skills idcounter="20"> with the entries and such following within it.

My question is, can I get that number through a function call on the Database Node? It would make what I'm attempting to do ten times easier.

Thanks!

Zeus
May 18th, 2011, 11:52
Not sure about reading the idcounter attribute specifically but you could always use the getChildCount() method for a databasenode.

drahkar
May 18th, 2011, 12:40
That works if you never delete an entry from the windowlist. Problem is that the idcounter (which is what is used to create the id-XXXXX entry continues to increment every time you create a new entry and doesn't reduce if you remove one.) I understand why its there. You don't risk overwriting an existing entry by doing it. But without a means of getting that attribute data, it makes it difficult to get a accurate reference of all the entries in the list. You can use a getChildren, which creates a table with all of the node objects in it, but the problem is that it assigns the index to them as the name of the entry instead of 1-X.

The result is that it works great if you already know what is there. But I'm trying to do a comparison that goes through and checks a node under each entry and compares it to a string I have in a variable. Without knowing the exact IDs of each entry I'm trying to figure out how best to implement this comparison. What would be awesome is if we could have getChildren() have an arguement of 'nodename' or 'index' where where nodename indexes the array by the name of the node and index does so with a number.

For example:



'table = databasenode.getChildren("nodename")'

would create a table that is indexed like:
'table["id-00003"]'

and:
'table = databasenode.getChildren("index")'

would create a table indexed like:

'table[1]'.

drahkar
May 18th, 2011, 13:20
What I've ended up having to do is a while loop that uses a string.format function to generate a series of id-XXXXX names to use based off of the i element for the while count. I then have added a buffer of 10 with the blind hope (at least until its gotten some use to see the practice of users) that people aren't likely to be deleting things more than 10 times. I'm trying to reduce the ineffency of the design. But its the only method I can think of to be able to do the kind of comparisons I need without being able to index the getChildCount to a number based system. (first entry is 1, second entry is 2, etc.)

Hey Moon? Any chance we could get something like this added to the getChildren() function in the future?

Zeus
May 18th, 2011, 14:12
The result is that it works great if you already know what is there. But I'm trying to do a comparison that goes through and checks a node under each entry and compares it to a string I have in a variable. Without knowing the exact IDs of each entry I'm trying to figure out how best to implement this comparison. What would be awesome is if we could have getChildren() have an arguement of 'nodename' or 'index' where where nodename indexes the array by the name of the node and index does so with a number.

Aye curumba, that would be a difficult approach. Instead I would use the pairs method to iterate through the list as it doesn't need to know the exact child node names to access the data e.g.



windowlistnode = windowlist.getDatabaseNode();

for k, v in pairs(windowlistnode.getChildren()) do
if v.achildnode.getValue() == myVariable then
-- do some action
end
end


You can then either compare the value or nodename of the childnodes to your variable.

drahkar
May 18th, 2011, 15:14
Hmm. Now there is an idea I'll have to try. Would dramatically cut back on code to do things as well.

Thanks for the suggestion. :)

Here is a question to pose as well. I've gotten the code for adding a entry to a windowlist's DBnode structure, but I need the windowlist to actually update it's display once that change has been put into place. By default it doesn't do so until it rebuilds (like by closing the window and re-opening it). Any suggestions?

Moon Wizard
May 18th, 2011, 20:06
If you add a child node to a database node used by a windowlistcontrol, it will receive an internal notification to build a new window for that database object using the windowclass specified in the windowlistcontrol definition. It should happen synchronously with the databasenode.createChild call. There are several instances of this behavior in the 4E ruleset.

Some thoughts on the id counter:

* The table returned by databasenode.getChildren() contains tuples of key, value; where the node name is the key and the databasenode object is the value.

* If you use databasenode.createChild() without parameters, it will automatically create a child node using the next available id tag.

* If you really need to determine the highest number used so far; iterate through the keys returned by getChildren(), use tonumber(string.sub(key, 4)), and keep the highest value. Add 1 and you have the next id number.

Cheers,
JPG

drahkar
May 19th, 2011, 09:53
Moon -

Thanks for clarifying the situation on adding nodes to the windowlist. It helped me track down a process issue I had in my code. Also thank you for the information that createChild worked that way. Both were extremely helpful.

Doc -
That alternate way of handling the entries was perfect. Thank you for pointing it out. :) It did exactly what I needed.