5E Product Walkthrough Playlist
  1. #1

    Extension Creation Help

    I am trying to create a (what I thought would be) relatively simple Extension, that would create a new UI element to display the number of Golden d20s the party has, which is a house rule we use. I was able to get it all created in its most basic form, but the numbers do not sync between the client and the host, and I am lost on how to make that connection.

    golden_d20_tracker.lua
    Code:
    -- Create a global variable to store the window instance
    local goldenD20Window = nil
    
    function onInit()
        -- Announce the extension loading
        ChatManager.SystemMessage("Golden d20s Extension Loaded")
    
        -- Create the UI
        createUI()
    	
    	-- Getting initial count
    	goldenD20Count = DB.getValue("campaign.golden_d20_count", 0)
    
        -- Register a callback to update the UI when the golden d20 count changes
        DB.addHandler("campaign.golden_d20_count", "onUpdate", updateGoldenD20Count)
    	
    end
    
    function createUI()
        -- Create a window to hold the Golden d20s UI
        goldenD20Window = Interface.openWindow("goldend20_window", "")
        if goldenD20Window then
            goldenD20Window.updateGoldenD20Count = updateGoldenD20Count
            goldenD20Window.increaseGoldenD20 = increaseGoldenD20
            goldenD20Window.decreaseGoldenD20 = decreaseGoldenD20
            updateGoldenD20Count()
        else
            ChatManager.SystemMessage("Failed to create Golden d20s UI")
        end
    end
    
    function increaseGoldenD20()
        local count = DB.getValue("campaign.golden_d20_count", 0)
        DB.setValue("campaign.golden_d20_count", "number", count + 1)
    end
    
    function decreaseGoldenD20()
        local count = DB.getValue("campaign.golden_d20_count", 0)
        if count > 0 then
            DB.setValue("campaign.golden_d20_count", "number", count - 1)
        end
    end
    
    function updateGoldenD20Count()
        if goldenD20Window then
            local count = DB.getValue("campaign.golden_d20_count", 0)
            goldenD20Window.golden_d20_count.setValue(count)
        end
    end
    windowclass.xml
    Code:
    <root>
        <windowclass name="goldend20_window">
            <frame>goldend20_window</frame>
            <placement>
                <size>
                    <width>70</width>
                    <height>80</height>
                </size>
            </placement>
            <sizelimits>
                <width>70</width>
                <height>80</height>
            </sizelimits>
            <playercontrol />
            <sharable />
            <noclose />
            <tooltip>
                <text>Golden d20</text>
            </tooltip>
      
            <sheetdata>
                <!--<windowreferencecontrol>
                    <bounds>15,11,20,20</bounds>
                    <class>note</class>
                    <description>
                        <field>golden_d20_title</field>
                    </description>
                </windowreferencecontrol>-->
                <genericcontrol name="panel_bg">
                    <bounds>0,0,70,80</bounds>
                    <icon>panel_bg</icon>
                    <anchor>
                        <vertical>center</vertical>
                    </anchor>
                </genericcontrol>
                <basicnumber name="golden_d20_count">
                    <bounds>25,30,20,20</bounds>
                    <readonly>true</readonly>
                    <align>center</align>
                </basicnumber>
    			
                <buttoncontrol name="decrease_golden_d20">
                    <bounds>25,53,20,20</bounds>
    				<icon>
    					<normal>g20_decrease</normal>
    				</icon>
    				<align>center</align>
                    <script>
                        function onButtonPress()
                            Interface.openWindow("goldend20_window", "").decreaseGoldenD20()
                        end
                    </script>
                </buttoncontrol>
    			
                <buttoncontrol name="increase_golden_d20">
                    <bounds>25,7,20,20</bounds>
    				<icon>
    					<normal>g20_increase</normal>
    				</icon>
                    <script>
                        function onButtonPress()
                            Interface.openWindow("goldend20_window", "").increaseGoldenD20()
                        end
                    </script>
                </buttoncontrol>
            </sheetdata>
        </windowclass>
    </root>
    ---


    Also, the other big piece that I was hoping to solve for was saving the "golden_d20_count" to an external text file, so I can call it in OBS to update/display the number to my Twitch chat.

    Any and all help would be appreciated!
    🎲 GM for the most Interactive TTRPG show on Twitch, Adventures from Amethil.
    📺 Watch ItsCliffGaming LIVE every Thursday @ 8pm, Eastern. [Click Here]
    🏆 Mention you are from the Fantasy Grounds Forums for Special Treatment.

  2. #2
    Any data that you want to be always be shared to the player clients has to be made public to the players. Try checking the code in CoreRPG for examples of DB.setPublic used for combattracker, party sheet and more.

    Regards,
    JPG

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
  •  
Dungeons & Dragons 2024 Core Rulebooks Pre-Order

Log in

Log in