PDA

View Full Version : Scripting token events



andirving
July 29th, 2007, 23:02
First off, let me state that I'm new to FG2 (well, FG) and I'm trying my hand at modifying scripts to handle a few things I'd like it to do.

I'm trying to take (scripted) action when a token on a map is clicked / double-clicked / etc. I notice that the pointer changes when over a token, and clicked events no longer fire in the image window when the token is clicked. I'm sure I'm missing it - can anyone tell me where this code would exist? Which .lua or .xml should I be looking at?

Next, in the imagewindow_image.lua file there's an onMeasureVector(token, vector) event that measures the length of the pending move segments for a token. I'd like to be able to affect that set of move segments. Is there a way to access that data otherwise? Specifically, I'd like to be able to remove segments (doesn't seem to be a way to undo the last new segment) and I'd like to be able to cancel the whole move, or create random movement.

Are these features exposed? If not, I'd love to see access to them in a future update.

Thanks

Spyke
May 11th, 2008, 10:53
I'm trying to take (scripted) action when a token on a map is clicked / double-clicked / etc. I notice that the pointer changes when over a token, and clicked events no longer fire in the image window when the token is clicked. I'm sure I'm missing it - can anyone tell me where this code would exist? Which .lua or .xml should I be looking at?I'd like to know the answer to this as well. I want to write a handler to change the way tokens react to rotation, but I can't figure out where to put this. As andirving says above, if we put handlers in imagewindow_image.lua they only seem to apply to the image, not the tokens on it. Should we be doing something with a function like populateFromImageNode?

Any help would be very much appreciated.

Spyke

joshuha
May 12th, 2008, 15:07
Right now the interfaces to tokens is pretty limited but there are plans to expose more functionality. The currently exposed functions are here: https://www.fantasygrounds.com/refdoc/tokeninstance.xcp

Generally to use these you can either use an imagecontrol and get a list of all the tokens via getTokens, do something to a token instance with the onTokenAdded part of an imagecontrol, or use the token control (like on the comabt tracker) to get a reference to tokens that are dropped from and do stuff.

Spyke
May 15th, 2008, 17:46
Thanks Joshuha. My issue's with how you write a handler that can be triggered when you interact with a token. I'd read through what was available from tokeninstance, but couldn't figure this out.

What I'd like to be able to do is to react to the onWheel event when the mouse is over a token (in order to write a different handler for token rotation). A script in the containing imagecontrol reacts to onWheel everywhere except over a token. I assume I can identify which token the mouse is over by comparing the position of the mouse with the bounds of each token associated with the imagecontrol, but I still can't figure out how to trap the onWheel event.

Sorry if I've missed something obvious.

Archmage
May 16th, 2008, 06:53
Right now the interfaces to tokens is pretty limited but there are plans to expose more functionality.
When? Can we get a time table with these "plans", or is this some sort of abstract notion involving any point in time that has not yet occurred? I'd really appreciate it if the developers were more clear about what's in the works right now, and what's on the drawing board. I think lots of others would appreciate that too.

joshuha
May 16th, 2008, 18:42
When? Can we get a time table with these "plans", or is this some sort of abstract notion involving any point in time that has not yet occurred? I'd really appreciate it if the developers were more clear about what's in the works right now, and what's on the drawing board. I think lots of others would appreciate that too.

I don't have exact times. I have a tracker where I can see the status of issues as they are resolved but its really the secondary tracker as the primary one is not in the English language.

I do have a list of the ones deemed public but thats pretty much everything in the FG wishlist thread and a few others. However, I can give you whats in there but not dates. I believe the devs are more cautious about dates becaues when FG2 went beyond their initial dates there was a near revolt heh. But I will see what I can wrangle out of them, maybe at least break it down by end-of-year, or quarters or something.

Archmage
May 17th, 2008, 19:37
Is there a way I can add an option to the radial menu on all tokens added to an image control? I tried accessing the onDrop() function in the image window, but it doesn't seem to return any dragdata.