Page 2 of 2 First 12
  1. #11
    celestian's Avatar
    Join Date
    Jan 2017
    DFW, Texas
    Something like this might work if I understand your goal.

    local sAttacks = "";
     for _,nodeAttack in pairs(DB.getChildrenGlobal(nodeRecord, "attacks")) do
      local nNumberOfAttacks = DB.getValue(nodeAttack, "numberOfAttacks", 1);
      local sSep = "";
      if sAttacks ~= "" then
       sSep = ", ";
      sAttacks = sAttacks .. sSep .. tostring(nNumberOfAttacks) .. DB.getValue(nodeAttack , "name") .. " (" .. DB.getValue(nodeAttack , "damage") .. ")";
    DB.setValue(nodeRecord, "attacks.numberattacks_text", "string", sAttacks);
    Last edited by celestian; January 24th, 2020 at 07:10.
    Coding the Official AD&D Ruleset
    My Twitch Channel for AD&D and FG related streams (See schedule for live days)
    My YouTube for FG related Tutorials and AD&D Actual Plays
    Custom Maps (I2, S4, T1-4, Barrowmaze,Lost City of Barakus)

  2. #12
    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
    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:

    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");
          sAttacks = sAttacks .. tostring(nNumberOfAttacks) .. " " ..
            Plural.lookup(DB.getValue(attack, "name"));
        sAttacks = sAttacks .. " (" .. DB.getValue(attack, "damage") .. ")";
        Debug.console("IDX=", count, "#Attks", nTypesOfAttacks)
        if count ~= nTypesOfAttacks then
          sAttacks = sAttacks .. ", ";
    Debug.console("AttkStr=", sAttacks);

    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 07:04.

  4. #14
    Trenloe's Avatar
    Join Date
    May 2011
    Newcastle, UK (for a bit)
    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?
    FG Con 16 Fantasy Grounds Online RPG Convention - Friday April 24th to Sunday April 26th, 2020
    Register at for all the latest info.

    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
    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)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Log in

Log in