PDA

View Full Version : A little help?



chillybilly
November 3rd, 2018, 15:51
I'm working on creating a tab for my player sheet to track stress. This is what it looks like.

25174

My problem is that when I click on a node (to either make it red or clear the red), I see the change but the client doesn't and vice versa. I feel like I'm missing something simple like telling the program to update on every click but I'm too computer illiterate to figure it out. Here is the part of the file dealing with the stresstrack.

25176

Any ideas?

Trenloe
November 3rd, 2018, 16:15
Generic controls (https://www.fantasygrounds.com/refdoc/genericcontrol.xcp) aren't anchored to a database field. So, you're right, you need to tell the control to update itself when the relevant database field/s update.

This is done by registering an update function against a database onUpdate handler: https://www.fantasygrounds.com/refdoc/databasenode.xcp#onUpdate

This is usually done via a DB.addHandler command in the onInit function that registers the local update function against the handler (onUpdate on this case). Info on DB.addHandler here: https://www.fantasygrounds.com/refdoc/DB.xcp#addHandler

You already have a function you want to run onUpdate - you've called it update - so you could use the following in the onInit function: DB.addHandler(window.getDatabaseNode().getChild(ge tName()), "onUpdate", update);

This will register the onUpdate handler for the note returned by DB.addHandler(window.getDatabaseNode().getChild(ge tName()) and will execute the update function whenever the value in that node changes.

Hope this all makes sense?

chillybilly
November 3rd, 2018, 16:37
Thank you for the response!

Okay, I think you're telling me to add

DB.addHandler(window.getDatabaseNode().getChild(ge tName()), "onUpdate", update);

to the onInit function so it now looks like this:

25177

But my problem is I get errors like this.

25178

It's okay if I'm too stupid to get this to work. It's falls on me to try to figure it out. Believe me, I LOVE the help these forums provide but I don't want to ask someone to do an hour of work for me. It's not fair to you guys.

Ken L
November 3rd, 2018, 16:59
You'll need both onAdd and onUpdate handlers to watch a particular node. It looks like you're using a radial control and you can save those radial values to the database.

onAdd is so when the value is initially added, it'll fire, else it would only fire on a subsequent update.

I would double check your addHandler syntax as that looks wrong. Follow the ruleset reference's specs as with ...getName() you're just getting the node name, you want to give it the full node path blah.dah.valueholder as opposed to "valueholder".

FG is an annoying API to work with, but given how much exposure it offers to create your own features, I accept it currently.

Trenloe
November 3rd, 2018, 18:55
Thank you for the response!

Okay, I think you're telling me to add

DB.addHandler(window.getDatabaseNode().getChild(ge tName()), "onUpdate", update);

to the onInit function so it now looks like this:

25177

But my problem is I get errors like this.

25178

It's okay if I'm too stupid to get this to work. It's falls on me to try to figure it out. Believe me, I LOVE the help these forums provide but I don't want to ask someone to do an hour of work for me. It's not fair to you guys.
Sorry, I didn't fully read the API - as Ken says, the first parameter should be a node path (string), node a database node. This: DB.addHandler(window.getDatabaseNode().getChild(ge tName()).getPath(), "onUpdate", update);

Maybe consider the following code. It's a little cleaner, and also checks that the node was created before trying to add a handler:

function onInit()
local nameNode = window.getDatabaseNode().createChild(getName(), "number");

if nameNode then
DB.addHandler(nameNode.getPath(), "onUpdate", update);
end

update();
end

I'm not sure if you'll need the additional onAdd handler that Ken mentions. I believe this onAdd is a handler for that fires when child nodes are added, not the adding of the first data value to a node. As you've already added the child node previously (using createChild) it would be too late for the onAdd handler to fire. And you're also running the update function after this in onInit, so it's basically performing a similar function to "onAdd" anyway.

Hope this helps.

chillybilly
November 3rd, 2018, 20:25
You are both so incredibly awesome. I can't say that I fully understand what you did but I can say that it worked! Thank you both so much for the help. I am constantly amazed at how much people help each other here. Thanks again!