5E Product Walkthrough Playlist
Page 1 of 2 12 Last
  1. #1

    Join Date
    Mar 2020
    Location
    Sydney, Australia
    Posts
    247

    Iterating Through All Characters In DB

    Greetings,

    so I can access DB Nodes without much of a problem, and I can access a specific character the same.

    However I would like to iterate through all characters to adjust a database node when something important changes.

    Is this possible? Or do I have to access one character at a time?
    Thanks In Advance,
    D

  2. #2
    When modifying all the records of a given type; you'll have to be careful to do it sparingly (infrequently), because you have no idea how many records of a given type that a campaign may contain.

    The new CharEncumbranceManager script in the Test/beta version does exactly this for PCs in a campaign, when the currency weight option is toggled or the campaign currency list is updated (both infrequent events). See the updateAllCharacters function.

    Regards,
    JPG

  3. #3

    Join Date
    Mar 2020
    Location
    Sydney, Australia
    Posts
    247
    Well the need for it is that I have a field that can be dynamically set by the GM in the settings panel - players are notified of the change via OOB.

    The problem is that since I cannot seem to get onEnter, onTab, or any of those events to trigger for a textbox in the settings panel I have had to resort to updating everytime the GM changes something.

    This then creates a new field with each new letter being something new so the characters end up with a list of useless data in their character data.

    So the idea is to clean out the previous entry as the GM changes the value in the textbox.

    D
    Thanks In Advance,
    D

  4. #4
    Try using delaykeyupdate on the fields that the GM edits to reduce the overhead of number of changes while they are editing. It will not update the database until the control loses focus with that tag.

    And/or try having a refresh button that will perform the updates once the GM is finished making changes. You could even track whether there have been changes since last refresh to warn the GM that there are pending changes.

    Regards,
    JPG

  5. #5

    Join Date
    Mar 2020
    Location
    Sydney, Australia
    Posts
    247
    Okay I have got the onEnter() and onTab() finally working.

    It is strange that if I do not put an entry into the control definition (XML) like
    Code:
    function onValueChanged()
        window.onValueChanged();
    end
    function onEnter()
        window.onEnter();
    end
    and then in the script file attached to the control

    Code:
    function onEnter()
        if enable_update and option_key
        then
            OptionsManager.setOption(option_key, getTextValue())
        end
    end
    the onEnter() will not trigger at all.

    I would term it strange since it would be assumed the script file would be used if attached to the control.

    Anyway I now do not need to worry about the database as this is working as expected.
    Thanks In Advance,
    D

  6. #6
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,411
    If window.onEnter runs your script onEnter function in the script file then that function is at the window level not at the control level.
    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!

  7. #7

    Join Date
    Mar 2020
    Location
    Sydney, Australia
    Posts
    247
    Well here's the rub ...

    I have a lua script for my textbox control which is included thus ...

    Code:
    <root>
    	<windowclass name="option_textbox">
    		<margins control="0,0,0,2" />
    		<script file="textbox.lua" />
    
    		<sheetdata>
    
    
    .. it looks exactly like a normal on/off control but with a textbox instead of the cycler in the definition.
    Then I try onEnter in Fantasy Grounds in the Option and it DOES NOT work.

    I then enter the window.onEnter() line into the script part of the control, thus ...

    Code:
    	<stringcontrol name="textbox">
    		<anchored width="100">
    			<top offset="5" />
    			<left parent="label" anchor="right" offset="25" />
    		</anchored>
    		<center />
    		<font>optionbody</font>
    		<script>
    			function onEnter()
    				window.onEnter();
    			end
    		</script>
    	</stringcontrol>
    And suddenly it works.

    textbox.lua looks exactly like the script for on/off options, however deals with textboxes.

    What is going on here then???
    Last edited by UrsaTeddy; February 21st, 2022 at 05:58.
    Thanks In Advance,
    D

  8. #8

    Join Date
    Sep 2020
    Location
    Ballston Lake, NY
    Posts
    600
    Starting with simple stuff, because sometimes we miss the obvious.

    Is your path to textbox.lua correct? Is it in the same folder as your control xml or in the scripts folder?

    Did you try a Debug on the first line of the OnEnter function to confirm it wasn't being called? What does
    Code:
    Debug.chat("OnEnter", enable_update, option_key)
    write to chat?

  9. #9

    Join Date
    Mar 2020
    Location
    Sydney, Australia
    Posts
    247
    ... Okay ...

    thank you for the suggestions ... I can 100% assure you I did what you are mentioning at the very beginning when I built the control (almost 2 years ago now). I had it working using onValueChanged() but my needs for it have changed and so I have been expanding, modifying, improving it.

    The control XML file is in the same directory as the control LUA file. It is included in the control XML using the path from the root of the extension to the file itself ... (the XML lies at "controls/textbox/textbox.xml").

    Code:
    <script file="controls/textbox/textbox.lua" />
    ... I then placed dummy code headers into my script file

    Code:
    function onValueChanged()
    	Debug.chat("onValueChanged")
    end
    function onLoseFocus()
    	Debug.chat("onLoseFocus")
    end
    function onGainFocus()
    	Debug.chat("onGainFocus")
    end
    function onNavigateUp()
    	Debug.chat("onNavigateUp")
    end
    function onNavigateDown()
    	Debug.chat("onNavigateDown")
    end
    function onTab()
    	Debug.chat("onTab")
    end
    function onEnter()
    	Debug.chat("onEnter")
    end
    ... because I originally wanted to see when they each fire, if there were multiple events firing and so forth.

    However I never received any of these messages in my chat window. Actually that is not true, onValueChanged worked because I had copied code from the Cycler option control and thus it had the onValueChanged() code from below in it.

    After asking around the boards, and searching, I was hitting a wall and so began to experiment.

    When I did the following in the <stringcontrol> that I was using ...

    Code:
    <script>
    	function onValueChanged()
    		window.onValueChanged();
    	end
    	function onLoseFocus()
    		window.onLoseFocus();
    	end
    	function onGainFocus()
    		window.onGainFocus();
    	end
    	function onEnter()
    		window.onEnter();
    	end
    	function onTab()
    		window.onTab();
    	end
    	function onNavigateUp()
    		window.onNavigateUp();
    	end
    	function onNavigateDown()
    		window.onNavigateDown();
    	end
    </script>
    All of the callbacks in the script file began to fire, just like the onValueChanged() callback.

    Thus my comment "here's the rub". It does not seem to be working like Trenloe and MoonWizard have suggested it should. Or there has been a miscommunication somewhere.
    Thanks In Advance,
    D

  10. #10
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,411
    What I eluded to in my post earier - you're running code in two different places - the windowclass level (window.) and the control level. Control events only fire at the control level.

    Windows (specified using <windowclass>) are containers that have one or more controls within the windowclass - code and events that run in a control doesn't automatically run in the windowclass - because the windowclass is not the control, it's at one level higher than the control. Hence why window.onValueChanged() works - because that is the event code in the control calling code in the windowclass (window.)
    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
  •  
STAR TREK 2d20

Log in

Log in