PDA

View Full Version : onHotKeyActivated problem



SpudmanWP
November 23rd, 2010, 22:05
I have two problems with this function.

Problem 1. It seems the documentation mentions it twice by mistake here (https://www.fantasygrounds.com/refdoc/Interface.xcp#onHotKeyActivated).


onHotKeyActivated

handler function onHotKeyActivated( dragdata )

The functions registered on this handler will be called whenever a hot key is pressed.

Parameters
dragdata (dragdata)
A dragdata object containing the state of values connected to the depressed hot key.

onHotKeyDrop

handler function onHotKeyDrop( dragdata )

The functions registered on this handler will be called whenever an object is dropped on the hot key bar.

Parameters
dragdata (dragdata)
A dragdata object containing the state of values connected to the mouse cursor as part of a drag and drop operation.

onHotkeyActivated

handler function onHotkeyActivated( draginfo )

The functions registered on this handler will be called whenever a hot key bar slot is activated. This allows the processing of custom drag types and context specific special operation.

Parameters
draginfo (dragdata)
The dragdata object representing the contents of the activated hot key bar slot

The first entry references when a hotkey is pressed and the second when a slot is activated. They also pass two different types of data (dragdata & draginfo).

Problem 2. I have a sample ext that I wrote using the above functions:

function onInit()
if ChatManager then
--ChatManager.registerSlashHandler("/KeyDmp", KeyDmp);
print ("ETUtility Loaded")
end
end

function onHotKeyActivated( myData )
print("ETUtility Hotkey Pressed")
print(myData)
ChatManager.addMessage(myData)
return true;
end

function onHotKeyDrop( myData )
print("ETUtility Hotkey Dropped")
print(myData)
ChatManager.addMessage(myData)
return true;
end

function onHotkeyActivated( myData )
print("ETUtility Hotkey Activated")
print(myData)
ChatManager.addMessage(myData)
return true;
end

I know that the ext is being loaded because the "ETUtility Loaded" message (from the onInit function) appears on the console. Whenever I use the hotkeys, nothing appears on the console.

Is there something I am missing?

Zeus
November 23rd, 2010, 23:53
I think the mistake is in the duplicate naming, the first function should really be named as onHotKeyPressed() or similar.

Anyhow, these I believe are Event handlers meaning to utilise you need to 'register' functions to handle the events or putting it another way, override the default event handlers with your own functions in onInit() e.g. something like:



function onInit()
if ChatManager then
ChatManager.registerSlashHandler("/KeyDmp", KeyDmp);
print ("ETUtility Loaded")
end

Interface.onHotKeyActivated = myonHotKeyActivated;
Interface.onHotKeyDrop = myonHotKeyDrop;
Interface.onHotkeyActivated = myonHotkeyActivated;

end

function myonHotKeyActivated( myData )
print("ETUtility Hotkey Pressed")
print(myData)
ChatManager.addMessage(myData)
return true;
end

function myonHotKeyDrop(myData)
print("ETUtility Hotkey Dropped")
print(myData)
ChatManager.addMessage(myData)
return true;
end

function myonHotkeyActivated(myData)
print("ETUtility Hotkey Activated")
print(myData)
ChatManager.addMessage(myData)
return true;
end


Think that should work, although a word of warning, hotkeys can hold non-text content, you should therefore check for the data type of myData before using print() or the ChatManager.addMessage routines, this will avoid possible error conditions from arising .

SpudmanWP
November 24th, 2010, 02:17
It did not like the use of:

Interface.onHotKeyActivated = myonHotKeyActivated;
Interface.onHotKeyDrop = myonHotKeyDrop;
Interface.onHotkeyActivated = myonHotkeyActivated;

It gave the following on each:

Script Error: [string "scripts/ETUtility.lua"]:7: attempt to set a value for an invalid handler 'onHotKeyActivated'

Moon Wizard
November 24th, 2010, 06:05
The handler options are: onHotkeyDrop and onHotkeyActivated.

Make sure you have the right capitalization.

Cheers,
JPG

SpudmanWP
December 17th, 2010, 04:14
That worked... I will make sure the capitalization is corrected in the helpfiles I am creating.

Bidmaron
December 28th, 2010, 22:28
Can we get the documentation fixed for the duplicate functions?

SpudmanWP
December 29th, 2010, 22:28
I let them know about it already. In the meantime, I have fixed it in my Unified Help Files.

I actually found about 5 errors so far.

https://www.fantasygrounds.com/forums/showthread.php?t=13849