FG Spreadshirt Swag

Thread: A little help?

  1. #1

    A little help?

    I'm working on creating a tab for my player sheet to track stress. This is what it looks like.

    CropperCapture[50].jpg

    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.

    CropperCapture[52].jpg

    Any ideas?

  2. #2
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,413
    Generic controls 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/refdo...e.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?
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

  3. #3
    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:

    CropperCapture[53].jpg

    But my problem is I get errors like this.

    CropperCapture[54].jpg

    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.

  4. #4
    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.

  5. #5
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,413
    Quote Originally Posted by chillybilly View Post
    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:

    CropperCapture[53].jpg

    But my problem is I get errors like this.

    CropperCapture[54].jpg

    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:
    Code:
    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.
    Last edited by Trenloe; November 3rd, 2018 at 18:57.
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

  6. #6
    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!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
STAR TREK 2d20

Log in

Log in