Add an array to control.dataEntry.data?
Hey,
is it possible to add an array to the dataEntry.data node of a control (e.g. an inventory item)? I've seen ResearchAssistant adding information there. And i've tried to do it the same way. But I'm not able to add information that are deeper then 1 value. Let's say this would work: control.dataEntry.data.newvalue = "Helo World" But this doesn't work: local ar = {} ar[1] = "Hello World" ar[2] = "Test" control.dataEntry.data.newvalue = ar It isn't even possible do add information with a depth of 2: control.dataEntry.data.newvalue.here = "Hello World" Any1 got an idea how to do this properly? Thanks. |
Your second example should work fine. Your third example won't because you're treating the newvalue key as a table (adding a key to it), but it hasn't been defined as a table yet (so you can't add a key to it).
|
But the 2nd one did not work. It was always telling me that the value is nil.
Only adding flat data directly to the dataEntry.data worked for me. |
What are you trying to do?
Actually putting something into the dataControl.data doesn't do anything by itself. If you look, the 'researchAssistant' field is not actually read out. The actual controls are created alongside it within the AddResearchIndicatorToSlot function. As such, I don't think there's really a restriction on subtables. The NIL indicator you get seems to indicate that whatever you put there isn't sticking around for when you need it. Depending on the ZOS control, the dataControl.data can be overwritten for a list refresh or a sort. As such, you'd need to hook into the callback creation of the dataControl and make sure that for each object created, your structure is there. researchAssistant does this with: Lua Code:
If you need something to stick around between those refreshes, put it in a local table for your addon. |
Quote:
|
Thx for the comments.
The addon we are talking about is FCOItemSaver. You are able to mark some items with icons and hide those items by filters, to prevent deconstruction/destroying/selling/trading of these items. I'm trying to populate the information which item of the inventories was marked with which icon/filter to the dataEntry.data tree. I know that the info must be added with the post-hook. Otherwise the data of the item isn't there and couldn't be used properly. I'm doing it exactly the same like katkat42 within ResearchAssistant's method "AddResearchIndicatorToSlot" and I'm using the post-hook from the deconstruction oanel, and the normal inventory. It is working fine, if I only add one entry (like ResearchAssistant does). But I wanted to add an entry "FCO", another sub-entry "ItemSaver" and then an arry "Marked {}" with the information which mark has been set for the current item. The current version of FCOItemSaver got 8 new entries "FCOItemSaverMarked1" to "FCOItemSaverMarked8", because the sub-entries and the array weren't working (always the error with nil). If someone got the time to review the code, or test it for themselves: Please feel free to do so. But it is not urgent! I've added some global functions to the addon so you are able to use them, instead of crawling the dataEntry.data trees. |
Baertram, do you mean something like this:
Since you said you wanted Marked to be a table I'm guessing items can have more than one mark? So you probably want something like this: NEW Function: to check and see if an item is already marked, don't want to mark an item twice: Lua Code:
Altered Function: FCOItemSaver_AddInfoToData(control)
Lua Code:
|
Thx I'll try this one out.
Perhaps it was all about the table.insert function, that I did not use... |
It could also be done without table.insert, we could assign a specific key refering to which mark it is.
Lua Code:
But then when you loop through it later to check marks you'de have to remember that there may be keys missing. For example if an item only had the 1st & 3rd mark: Lua Code:
Lua Code:
table.inert just makes it easier by ensuring the none of the keys for the table are missing so we dont have to worry about it later when searching through the table (but not the only way to do it). It could also be done like this, if you only wanted to add 1 marker: Lua Code:
or if you wanted to name them Lua Code:
|
All times are GMT -6. The time now is 01:02 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI