PDA

View Full Version : Certain windowinstance handlers are being reported as invalid



Gkjsdll
May 6th, 2018, 20:54
function onWindowOpened(window)
-- Do not produce error
window.onLockChanged = test
window.onMove = test
window.onShare = test
window.onSizeChanged = test
window.onViewersChanged = test

-- Script Error: attempt to set a value for an invalid handler [handler_name]
window.onDrop = test;
window.onSubwindowInstantiated = test
window.onMenuSelection = test
window.onInit = test
window.onClose = test
window.onHover = test
window.onHoverUpdate = test
end
Interface.onWindowOpened = onWindowOpened;

I tested all of the "invalid" handlers using the 5e ruleset, and I also tested onDrop using 3.5e, 4e, corerpg, fate core, numenera, & pfrpg on FG v.3.3.5

Is there some other way to assign these handlers? Is this a bug in FG? I am specifically trying to use onDrop as onMove is having too much impact on performance.

Trenloe
May 6th, 2018, 21:04
What are the exact errors you're getting?

Is test a valid LUA function?

Gkjsdll
May 6th, 2018, 21:20
extension.xml

<?xml version="1.0" encoding="iso-8859-1"?>
<root release="3.3.1" version="3.3.1">
<properties>
<name>windowinstance handler testing</name>
<version>-</version>
<author>Zack (Gkjsdll) Winchell</author>
<description>Tests windowinstance handler functions</description>
</properties>
<base>
<script name="tests" file="tests.lua" />
</base>
</root>
tests.lua

function onInit()
function onWindowOpened(window)
-- Do not produce error
window.onLockChanged = test
window.onMove = test
window.onShare = test
window.onSizeChanged = test
window.onViewersChanged = test

-- Script Error: attempt to set a value for an invalid handler [handler_name]
window.onDrop = test;
window.onSubwindowInstantiated = test
window.onMenuSelection = test
window.onInit = test
window.onClose = test
window.onHover = test
window.onHoverUpdate = test
end

function test()
Debug.console("a handler was triggered");
end

Interface.onWindowOpened = onWindowOpened;
end

errors


Script Error: [string "tests.lua"]:11: attempt to set a value for an invalid handler 'onDrop'

All of the handlers below the "Script Error" comment produce the same error if I comment out the earlier invalid handler assignments.

Moon Wizard
May 8th, 2018, 22:07
There is a distinction that the original developers of Fantasy Grounds made for setting up handlers vs. events. The distinction is that a handler can be assigned from any script, while an event function must be defined in an attached script. If you look at the definition of the event/handler in the API reference, you'll see a tag that defines whether it's an event or handler.

For several object types, it makes sense that handlers are used, since the objects can not support attached scripts (tokeninstance, databasenode). Thus, they can not support events.

However, some of the objects were given both handlers and events that do support attached scripts. (such as windowinstance and windowcontrol) I'm not sure why the original developers chose this route for these object types; it was before my time. If I were to design this now, all window events would be "events" (i.e. script defined), and a few would have global handlers as needed(such as onWindowOpened and onWindowClosed).

Regards,
JPG

Gkjsdll
May 8th, 2018, 22:31
I see now the text on the right that says event or handler, but I can't find where the docs make a distinction between the two. By API reference, are you referring to https://www.fantasygrounds.com/refdoc?

Sorry if my noob shows here, but I can't seem to find any info online about standard event listener assignments in lua. Is there some way to do this in FG, or are you saying that extensions cannot make use of event listeners?

Trenloe
May 8th, 2018, 22:36
I see now the text on the right that says event or handler, but I can't find where the docs make a distinction between the two.
https://www.fantasygrounds.com/wiki/index.php/Developer_Guide_-_Rulesets_-_Scripting#Using_Events


By API reference, are you referring to https://www.fantasygrounds.com/refdoc?
Yep.

Moon Wizard
May 8th, 2018, 22:59
Sorry if my noob shows here, but I can't seem to find any info online about standard event listener assignments in lua. Is there some way to do this in FG, or are you saying that extensions cannot make use of event listeners?


Event listeners can not be assigned from other scripts. They must be defined in the script attached to the object. If you want to add events, you will need to override the script for that object.

Regards,
JPG

Gkjsdll
May 8th, 2018, 23:08
Event listeners can not be assigned from other scripts. They must be defined in the script attached to the object. If you want to add events, you will need to override the script for that object.

Regards,
JPG

Aww :(

Thank you both for helping me learn about this.