PDA

View Full Version : databasenode = { image.id-00002.image } from tokeninstance getContainerNode



SilentRuin
September 15th, 2021, 23:28
I'm trying to figure out how to get the actual tokeninstance DB node so I can access the <fow> data for it. But it seems I have to do it manually - so I went and called



local nodeContainerOld = oldTokenInstance.getContainerNode();
for _,oldnodeLayer in pairs(DB.getChildren(nodeContainerOld, "layers")) do
...


But I can never find layers. In fact, using the container node to access any of the values under this node (in my case its databasenode = { image.id-00002.image } ) also return nil.

I'm not sure why a node that supposedly references the object that holds the tokeninstance cannot actually reference anything under it. I'd be open to an alternative way of just getting the db.xml node for the tokeninstance if there is an alternate way to get this.

jharp
September 15th, 2021, 23:50
*ahem* I will plug FoWEnhanced here (in the forge store). You are completely correct that you can't access anything under the image.id-00000.image object through any calls to the DB. I do hope to add more features to FoWEnhanced if you have any particular needs.

SilentRuin
September 16th, 2021, 00:03
*ahem* I will plug FoWEnhanced here (in the forge store). You are completely correct that you can't access anything under the image.id-00000.image object through any calls to the DB. I do hope to add more features to FoWEnhanced if you have any particular needs.

Yes this is very specialized <fow> use as my polymorphism extension replaces tokens and more but loses the <fow> data - so all I'm trying to do is Access the data for the old and the new so it translates down in my replace token code and copies over the old one. Nothing to do with what I'm reading this thing does.

jharp
September 16th, 2021, 00:15
I'll add an appropriate API to the next build. I'm thinking getFoW(token) returns FoW as string and setFoW(token,string). If you have some other API in mind I can try that. However, I'm not certain how this might work to have other people need to have my extension to have your work. Maybe some price sharing arrangement is better and the functionality simple gets put directly into your code.

If interested we can discuss in discord at some point.

SilentRuin
September 16th, 2021, 00:18
I'll add an appropriate API to the next build. I'm thinking getFoW(token) returns FoW as string and setFoW(token,string). If you have some other API in mind I can try that. However, I'm not certain how this might work to have other people need to have my extension to have your work. Maybe some price sharing arrangement is better and the functionality simple gets put directly into your code.

If interested we can discuss in discord at some point.

I'll just figure out the standard XML DB.xml way of grabbing it and post it here when I do - its not going to be all that big of a deal. Just wondered if someone knew how to do it.

FyreM
September 16th, 2021, 01:09
I'll add an appropriate API to the next build. I'm thinking getFoW(token) returns FoW as string and setFoW(token,string). If you have some other API in mind I can try that. However, I'm not certain how this might work to have other people need to have my extension to have your work. Maybe some price sharing arrangement is better and the functionality simple gets put directly into your code.

If interested we can discuss in discord at some point.
even if SilentRuin doesn't need it, can you please still add those API calls, as others systems that swap tokens may want to use this, thanks!

jharp
September 16th, 2021, 01:14
I've added it to my todo list. If you have any suggested api needs let me know in my main thread.

SilentRuin
September 16th, 2021, 19:21
Well, while I can edit it into the db.xml on the fly in the lua code - I can't seem to access the inline memory of the token for the underlying tags of the image object which is essentially an imagecontrol. As I need to do this at runtime with the currently defined data in FGU memory and also replace another set of data loaded into FGU memory - I can't find a way to do that without Moon Wizard providing an API into that ares of the tokeninstance data.

If there is a way to do that to the inline memory then I'm not finding it. I'll have to wait till an API in FGU comes out giving access to all of the tokeninstance live data.

Simply editing the db.xml worked but did not solve my runtime issues.

SilentRuin
September 16th, 2021, 21:31
MeAndUnique and I have been hashing this out and will try one more approach based on his input. Still requires some trial and error as its evident that the pain in the butt export code from /export still removes the tokens but db.export does not. Why these things are so different everywhere I have no idea but it makes figuring out this stuff 10 times longer. This will be my last attempt to get a runtime update in the middle of my code - will post here the results.

SilentRuin
September 16th, 2021, 23:55
Giving up - I'd have to manually parse the XML string (mostly because Utility.decodeXML loses data and Utility.encodeXML will not generate the original string) - copy the data over into the new id - which of course is not even there as I'd have to force a save before I read the XML string.... just too much hassle. I think it would work if I knew how to force a save of the campaign which would of course would delay the runtime (not acceptable) - and delete my temp xml I'm creating as they disabled os.remove in FGU.

If anyone wants to see the gist of where I was heading - and gave up on due to above statments... This was in code for replacing the token with another (losing the FOW). So just going to wait for Moon Wizard to supply an API to get/set the FOW in runtime memory.



-- create an xml file with the old image data
local sPath = File.getCampaignFolder() .. "PolyTokenTemp.xml";
DB.export(sPath, nodeContainerOld.getParent());
local sData = File.openTextFile(sPath);
-- extract the id for the old token
local oldID = oldTokenInstance.getId();
-- extract the fow tag from the old xml string
-- find the id for the new token and add/replace old fow data into it
local newID = newTokenInstance.getId();
-- write the new image xml node out to file
File.saveTextFile(sPath, sData);
-- import the new image xml node from file
DB.import(sPath, newTokenInstance.getContainerNode().getParent());


This will output the image data with the fow info for sure but in my world will actually fail later because the new ID was not in the file (only memory) wiping it out when imported. To much of a pain to bother with - but supplying what I did in case others don't need runtime instant workability.

jharp
September 17th, 2021, 00:20
Moon,

Any plans to provide an API to access the FoW data in the near future?

Jason

Moon Wizard
September 17th, 2021, 04:22
Not in the near future. The data has been in flux a bit over the year with lighting/vision/fow/los changes; and I don't want to lock us into a set of APIs at this point. We do have plans eventually, but no announced plans.

Regards,
JPG

DCrumb
September 17th, 2021, 16:05
@SilentRuin, would that code be able to be used at image close to retain FoW on a map and be able to bring it back on image open?

SilentRuin
September 17th, 2021, 17:07
@SilentRuin, would that code be able to be used at image close to retain FoW on a map and be able to bring it back on image open?

Probably, you'd have to try it. I was trying to solve a specific problem in polymorphism where when a PC/NPC transforms to another NPC and the token changes and loses the previous FOW (obviously as its a new token). I wanted to preserve the previous FOW in the newly created token between transformations. Was simply to painful to bother with for the reasons I stated. But if your not concerned with runtime and doing it simply on shutdown of app and startup of app it should be fine. But there would always be risk you'd mess something up as things can crash leaving some old bogus .xml out there that would destroy your previous data. Personally, I'll wait till FGU comes up with the API as its too risky without putting in a bunch of safeguards for me to mess with something like that. But feel free.