Log in

View Full Version : How do I add a button to the desktop that runs a script when clicked?



AlkarGreener
December 22nd, 2020, 11:09
I have created a script and registered it as a chat command. I want to add a button next to the dice that runs the same script.

I have created a class and added it to the desktop by copying and modifying other items, and have tried calling the script using the <script> tag with no luck. Any assistance is welcome.

<windowclass name="wilddiewindow"> <!-- match die size & alignment, etc. in the future -->
<backcolor>ffe81f</backcolor>
<sizelimits>
<dynamic />
<minimum width="64" height="64" />
</sizelimits>
<sheetdata>
<buttoncontrol template="button_wilddie">
<anchored position="insidetopleft" offset="2,2" width="48" height="48" />
<state icon="wd6icon" />
<tooltip>
<text>Wild Die</text>
</tooltip>
</buttoncontrol>
</sheetdata>
</windowclass>


<panel name="wildiewindow" modes="host,client">
<class>wilddiewindow</class>
<bounds>5,-100,64,57</bounds>
<dynamic />
<locked />
</panel>

Trenloe
December 22nd, 2020, 11:31
Moved to The Workshop forum. This is the best place to discuss FG coding.

Is the button appearing on the desktop? It doesn't look like you've correctly defined that button control. It should be <buttoncontrol name="button_wilddie"> unless you're using a template, in which case the syntax is different - plenty of examples within FG ruleset code to look at.

Did you attach the code to the onButtonPress event of the button control? https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996644896/buttoncontrol#onButtonPress

AlkarGreener
December 22nd, 2020, 12:34
I resolved it by adding onButtonPress to the script and tagging the script in the button.

Thanks for the assist.