PDA

View Full Version : NPC DB - CT correlation



Stv
July 4th, 2020, 12:20
Another proably stupid question :

If I have the DB node of an NPC in the CT, how do I get the window reference to that NPC in the CT so I can use things like window.setFrame etc.


Cheers, Steve.

damned
July 4th, 2020, 14:31
I dont understand the Q.
When you add a NPC to the CT it creates a copy of the NPC in the DB.
That is because the bulk of NPCs are dupes.

Stv
July 4th, 2020, 14:57
I'm not explaining myself very well :P , so here's a quick example :

If I have 2 actors in the CT let's call them npc1 and npc2.
I want to be able to change the graphical frame surrounding them n the combat tracker window.
So by my understanding to be able to do this via 'npc1window.setFrame' (paraphrasing the command to do so) then I would need to have npc1's window reference inside of the combat tracker window.
This is what I'm struggling with.

I hope that's clearer, and I also hope you can help :D

Cheers, Steve.

Trenloe
July 4th, 2020, 15:08
You'll need to get the windows from the CT windowlist, iterate through them until you find one with the same database node - don't use the NPC name as that isn't unique.

Get the windows in the CT using the windowlist getWindows API command: https://fantasygroundsunity.atlassian.net/wiki/spaces/FGU/pages/4162373/windowlist#getWindows

Then iterate through using for key,window in pairs(windowlist.getWindows()) do... Window is the window instance for each CT entry as you iterate through.


Then use getDatabaseNode: https://fantasygroundsunity.atlassian.net/wiki/spaces/FGU/pages/4096479/windowinstance#getDatabaseNode and getNodeName: https://fantasygroundsunity.atlassian.net/wiki/spaces/FGU/pages/4063650/databasenode#getNodeName to get the database node name the window is sourced from, and compare that with the database node name of the NPC CT record - then you'll have the window instance of the CT entry, and can do GUI "stuff" against that.

Stv
July 4th, 2020, 15:23
Thanks for the reply Trenloe.
I'm now going to show my ignorance

Get the windows in the CT using the windowlist getWindows API command: https://fantasygroundsunity.atlassia...ist#getWindows (https://fantasygroundsunity.atlassian.net/wiki/spaces/FGU/pages/4162373/windowlist#getWindows)
This is the bit I'm really having a hard time with, I can't seem to find the correct way of writing this.
Can you point me to a code example ?

Cheers, Steve.

*edit*
I meant to add that I'm attempting this from within my own functions, not from within the CT window instance.

Stv
July 4th, 2020, 19:19
So to further clarify,
using getWindows() in CT.lua returns the window references to the CT actors, which is what I need.
So I need to know how to get this functionality from within my main lua file which is not immediatley associated with the CT.lua functions.

Cheers, Steve.

Stv
July 5th, 2020, 10:49
I 've come up with a dirty workaround. It's messy but it works.
From within the ct.lua onInit function I store the 'self' value in a global variable. This is a pointer to the combat tracker windows that I need to reference elsewhere.
I'm sure there's a much better solution, but this works for now, until I can figure out how to do this better.

Cheers, Steve.

Trenloe
July 5th, 2020, 11:06
To get the top level Combat Tracker window instance use Interface.findWindow("combattracker_host", "combattracker"); on the GM side. https://fantasygroundsunity.atlassian.net/wiki/spaces/FGU/pages/4096375/Interface#findWindow

If you want to do this on the PC side substitute combattracker_client for combattracker_host.

Stv
July 5th, 2020, 13:58
Thanks Trenloe,
That's not what I'm after though. the 'self' from ct.lua returns a windowlist with the actor windows contained in it, whereas the interface.findwindow returns the windowinstance of the combat tracker and I'm too dumb to figure out how to use the windowinstance to get the information I need :P

Cheers, Steve.

Trenloe
July 5th, 2020, 14:18
The window instance returned is created with the combattracker_host windowclass - defined in ct_host.xml.

Within that windowclass are all the CT controls - including list_ctbox_host which is the windowlist control you're looking for.

<windowinstance>.<control name> gives the control. So, if you use local wCT = Interface.findWindow("combattracker_host", "combattracker"); to get the windowinstance of the CT, wCT.list_ctbox_host will give you the windowlist control.

Stv
July 5th, 2020, 14:24
Once again you have come up with a solution for me.
Thanks Trenloe, you're a legend :)

Cheers, Steve.

Trenloe
July 5th, 2020, 14:29
I don't know where your script is running. But if it's outside of the CT, then you'll need to check that wCT (in my example above) isn't nil before getting the windowlist control. Use if wCT then...

Stv
July 5th, 2020, 14:31
wCT is fine, it returns the combattracker windowinstance, but wCT.list_ctbox_host reurns nil. Here's my testing code, what am I doing wrong ?


local wCT = Interface.findWindow("combattracker_host", "combattracker")
Debug.console("wCT",wCT)
local tmp=wCT.list_ctbox_host
Debug.console("tmp",tmp)


Cheers, Steve.

Trenloe
July 5th, 2020, 14:38
Which ruleset are you using again?

Stv
July 5th, 2020, 14:42
It's 5e.
Think I've got it though...
I think local tmp=wCT.list is what I needed.

Thanks you again for your assistance, invaluable as ever :)

Cheers, Steve.

Trenloe
July 5th, 2020, 14:46
Yep, use .list - the control is named "list" within the list_ctbox_host template.