Starfinder Playlist
  1. #1

    Automatically update label value

    This seems like it should be easy, and I have read how to add handlers and custom handler functions, but the tricks I am using aren't working so far.

    So let's say I have a simple function in a char manager script file (extraneous checks omitted):

    Code:
    function calcEncumbrance(nodeChar)
      local enc = DB.getValue(nodeChar, "encumbrance.load");
      local st = DB.getValue(nodeChar, "attributes.strength");
      // calculate encumbrance, generate a string value, e.g. "Heavy", "Light", "None", etc.
      return encumbranceString;
    end
    I want it to be used like so:

    Code:
    			<frame_char name="encumbranceframe">
    				<bounds>15,-219,240,-15</bounds>
    			</frame_char>
    			<simplenumber name="encumbranceload" source="encumbrance.load">
    				<script>
    					function onValueChanged()
    						// want to fire off a signal here to make "encumbrance" call changeMyvalue()
    					end
    				</script>
    				<anchored to="encumbranceframe" position="insidetopleft" offset="160,30" width="55" height="20" />
    				<frame name="fieldlight" offset="7,5,7,5" />
    				<readonly />
    			</simplenumber>
    			<label name="encumbrance_label">
    				<anchored to="encumbranceframe" position="insidetopleft" offset="15,30" />
    				<static textres="char_label_totalweight" />
    			</label>
    			<label name="encumbrance">
    				<anchored to="encumbranceframe" position="insidetopleft" offset="15,60" />
    				<script>
    
                                             function onInit()
                                                 changeMyValue();
                                             end
    
    
    					function changeMyValue()
    						local charNode = CharacterManager.getCharsheet(window);
    						local sEnc = CharacterManager.calcEncumbrance(charNode);
                                                    setValue(sEnc);
    					end
    				</script>
    			</label>

  2. #2
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,402
    Moved this thread to the Workshop forum, which is the correct place to ask about coding advice.
    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
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,402
    Where your red entry is put encumbrance.changeMyValue();

    See the [control_name] scope mentioned here: https://www.fantasygrounds.com/wiki/...pt_Block_Scope
    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!

  4. #4
    Thanks - the block scope helped (I think I skimmed over that before). But calling encumbrance directly from a "sibling" control didn't work. What did work was window['encumbrance'].changeMyValue().

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
  •  
FG Spreadshirt Swag

Log in

Log in