STAR TREK 2d20
Page 2 of 2 First 12
  1. #11
    Varsuuk's Avatar
    Join Date
    Dec 2015
    Location
    New York
    Posts
    2,075
    Yuppers, I am definitely will be able to use that as well. Because I am also maintaining both internally. I just wanted to have an AC display that does not display either directly - just combines them into one string (original intended as a UI only control but for now giving up since haven’t see code to update a control for some reason anywhere yet)

    In dB, as I listed above - 2 seperatr sub fields to defenses. In UI, a single displayed value: “8 [11]”, which for now ... I’ll deal with it being another stringFIELD instead. For now.

  2. #12
    Varsuuk's Avatar
    Join Date
    Dec 2015
    Location
    New York
    Posts
    2,075
    Of course, now the I go to my NEXT UI element I see I need to again switch from my intention of UI element to DB field.

    I store attacks in DB where there may be multiple attack types and my intent was to present this to users in UI front page (vs when USING them and they list separately) summary as:
    "2 Claws (1d6), 1 Bite (1d8)"

    Of course, after writing this, I realize it will be a pain to ensure plural handling well... my initial writing (which I have never run since still building out) was done quickly without considering not everything is bite/claw/kick/etc (was looking at limited monsters)

    Code:
    function onAttacksChanged()
      local aAttacks = DB.getChildren(nodeChar, "attacks");
      local nTypesOfAttacks = #aAttacks;
      local sAttacks = "";
      
      
      for idx,attack in ipairs(aAttacks) do
        local nNumberOfAttacks = DB.getValue(attack, "numberOfAttacks", 1);
        local bIsMoreThanOneAttack = (nNumberOfAttacks > 1);
        
        sAttacks = bIsMoreThanOneAttack and toString(nNumberOfAttacks) or ""
          .. DB.getValue(attack, "name") .. bIsMoreThanOneAttack and "s" or ""
          .. " (" .. DB.getValue(attack, "damage") .. ")";
        
        if idx ~= nTypesOfAttacks then
          sAttacks = sAttacks .. ", ";
        end
      end
    end
    So, I will not autopen it but include it as a DB field in monster manual to be displayed. The DOWNSIDE of this is twofold chances of user error. I can enter two non-matchin settings. The entry might say "1 Bite(1d8)" and the body like:

    Code:
    		<attacks>
    			<bite>
    				<name type="string">Bite</name>
    				<damage type="string">1d6</damage>
    				<numberOfAttacks>1</numberOfAttacks>
    			</bite>
    			<claw>
    				<name type="string">Claw</name>
    				<damage type="string">1d8</damage>
    				<numberOfAttacks>2</numberOfAttacks>
    			</claw>
    		</attacks>
    Thing is anyone who codes a lot of data knows typos or mistakes happen and the two entires which should be 100% identical, can be inconsistent or even more likely, drift apart if someone edits one without remembering to edit the other matching field.




    As I wrote this ... I realized I COULD create a simple plural map config table where did. Plurals["Claw"] = "Claws". etc. but I digress ... will make a note of it for later...

  3. #13
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,361
    Quote Originally Posted by Varsuuk View Post
    But I haven't yet found any code to even change the value on a non-db control. I should keep looking through code, it HAS to exist, just don't know what to look for. That self[controlname] seemed a good lead.
    To answer this question - see the API documentation: https://www.fantasygrounds.com/refdo...l.xcp#setValue

    To access controls in the GUI hierarchy use <scope>.<control name>

    Where scope is detailed here: https://www.fantasygrounds.com/wiki/...pt_Block_Scope

    For example, if you wanted to access a control called acasc within the same window where the code is running use window.acasc

    So, to set a number control to 10: window.acasc.setValue(10);
    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!

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
  •  
DICE PACKS BUNDLE

Log in

Log in