Starfinder Playlist
Page 2 of 2 First 12
  1. #11
    Something like this might work if I understand your goal.

    Code:
    local sAttacks = "";
     for _,nodeAttack in pairs(DB.getChildrenGlobal(nodeRecord, "attacks")) do
      local nNumberOfAttacks = DB.getValue(nodeAttack, "numberOfAttacks", 1);
      local sSep = "";
      if sAttacks ~= "" then
       sSep = ", ";
      end
      sAttacks = sAttacks .. sSep .. tostring(nNumberOfAttacks) .. DB.getValue(nodeAttack , "name") .. " (" .. DB.getValue(nodeAttack , "damage") .. ")";
     end
    
    DB.setValue(nodeRecord, "attacks.numberattacks_text", "string", sAttacks);
    Last edited by celestian; January 24th, 2020 at 06:10.
    ---
    Fantasy Grounds AD&D Reference Bundle, AD&D Adventure Bundle 1, AD&D Adventure Bundle 2
    Documentation for AD&D 2E ruleset.
    Custom Maps (I2, S4, T1-4, Barrowmaze,Lost City of Barakus)
    Note: Please do not message me directly on this site, post in the forums or ping me in FG's discord.

  2. #12
    Varsuuk's Avatar
    Join Date
    Dec 2015
    Location
    New York
    Posts
    2,075
    You guys ABSOLUTELY rock!

    1. Yes, I have no CLUE when or IF I'd have figured out the sparse array thing. I am aware of the difference but it never occurred to me to switch to index - at least for a long time. Once I did this, the issue of failing to iterate properly went way. I switched to getChildCount() instead of # operator and that solved the odd numbers returned (Celestian, #ofAttacks as a field was different than numberOfAttkEntries (which isn't what I called it -so that's why it was confusion - #attk referred to overall how many entries so I knew when I was at the last one - will be clearer when done tonight or tomorrow and post the fixed version. Have to put boy late to bed.)

    2. Celestian, yeah - I know I started trying a version of "self[numberattacks_text_label].setValue(sAttacks);" because of misunderstanding use of self[control].update(...) code that was already there - BUT I thought I DID try it straight - I must have done something wrong, because it worked when I tried it on a label field. Will redo the control to emulate look of the stringcolumnleft control before finishing.

    Seriously, than you for solutions and forever the patience.

  3. #13
    Varsuuk's Avatar
    Join Date
    Dec 2015
    Location
    New York
    Posts
    2,075
    Debug printout:
    Runtime Notice: Reloading ruleset
    ...
    Runtime Notice: s'AttkStr=' | s'1 Bite (1d6), 2 Claws (1d6)'

    I had to leave off on the control template to sleep but the code showing a logging of the output *so far* is:

    Code:
    function onAttacksChanged(nodeRecord)
      local aAttacks = DB.getChildren(nodeRecord, "attacks");
      local nTypesOfAttacks = DB.getChildCount(nodeRecord, "attacks");
      Debug.console("onAttacksChanged", nodeRecord, nTypesOfAttacks);
      local sAttacks = "";
      
      local count = 0;
      for idx,attack in pairs(aAttacks) do
        count = count + 1;
      Debug.console(idx, "Attk:", attack.getNodeName(), attack);
        local nNumberOfAttacks = DB.getValue(attack, "numberOfAttacks", 1);
        
        if nNumberOfAttacks == 1 then
          sAttacks = sAttacks .. tostring(nNumberOfAttacks) .. " " ..
            DB.getValue(attack, "name");
        else      
          sAttacks = sAttacks .. tostring(nNumberOfAttacks) .. " " ..
            Plural.lookup(DB.getValue(attack, "name"));
        end
        
        sAttacks = sAttacks .. " (" .. DB.getValue(attack, "damage") .. ")";
        Debug.console("IDX=", count, "#Attks", nTypesOfAttacks)
        if count ~= nTypesOfAttacks then
          sAttacks = sAttacks .. ", ";
        end
      end
      
    Debug.console("AttkStr=", sAttacks);
      numberattacks_text.setValue(sAttacks);
    end

    That said, any reason NOT to use a "control" vs calculating it once and storing in the NPC-DB?
    I just didn't want to fill it up with fields that are nothing other than combinations of existing fields. But if there is a big cost to the control way, I would reconsider.

    In this case (and of "AC Down [Up]") I do not need to ever do anything with the string other than show it to folks.
    Last edited by Varsuuk; January 24th, 2020 at 06:04.

  4. #14
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,362
    If all the control is ever going to do is show it, it's never going to be accessed by any code and the value is set by code within the same GUI window, then a control rather than a field, is OK.

    Are you going to be displaying this data in then combat tracker fields?
    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!

  5. #15
    Varsuuk's Avatar
    Join Date
    Dec 2015
    Location
    New York
    Posts
    2,075
    Nope, merely a nicer formatted (space-saving) way of displaying the underlying fields that will be referenced.

    If I were to use that underline click thing feature and use this string elsewhere I’d save it. I wasn’t sure it was efficient to keep calculating it each time it is loaded due to the concatenation (Leery of string concatenation in the real time apps I work with, habit) but figured it’s a thing to keep in sync if I make it a data field, separately editable.

    So making it a derived field actually in the DB is best middle ground other than (IMO) cluttering up the stored npc. But if I need it anywhere else, then yes, I would change it.

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
  •  
5E Character Create Playlist

Log in

Log in