Are you aware of this: onChangeSelection

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

User avatar
Rumble
Deity
Posts: 6235
Joined: Tue Jul 01, 2008 7:48 pm

Re: Are you aware of this: onChangeSelection

Post by Rumble »

My tests are done with a mostly empty frame (designed specifically to test the number of outputs), and that's where 4 repeats of the output come from. I don't know why I get that many, though; the code seems to indicate that it should fire a maximum of three times.

User avatar
toyrobots
Dragon
Posts: 278
Joined: Sat Apr 12, 2008 4:17 pm

Re: Are you aware of this: onChangeSelection

Post by toyrobots »

Has anyone made any progress with making onChangeSelection more reliable?

I keep thinking how neat it would be to have a default attack or spell macro hooked up so that you could click enemy tokens Diablo-style.

User avatar
Rumble
Deity
Posts: 6235
Joined: Tue Jul 01, 2008 7:48 pm

Re: Are you aware of this: onChangeSelection

Post by Rumble »

AFAIK, nobody's doing any work on it - it is what it is.

User avatar
skester
Giant
Posts: 213
Joined: Mon May 04, 2009 3:44 pm

Re: Are you aware of this: onChangeSelection

Post by skester »

If you just change the properties manually or with a macro that doesn't refresh the frame, then no, the frame won't be updated.
I just noticed something last night, and it could be due to a cold induced daze, I'm not sure.

But when I have a macro up using onChangeSelection that displays a token property (Say Current Hit Points), and I make a manual change to it, it automatically updates. It seems to relaunch the macro without having to call it again.

This makes things a lot easier. I can have the quick sheet show numbers for stuff and when they change (due to bless, bard song, etc), it updates so the players can see.

Very cool!

Once again, maptools ROCKS!

Skester
(still in a cold induced daze and enjoying it)

prestidigitator
Dragon
Posts: 317
Joined: Fri Apr 23, 2010 8:17 pm

Re: Are you aware of this: onChangeSelection

Post by prestidigitator »

So it seems pretty obvious when 'onChangeImpersonated' and 'onChangeSelection' fire, but what about 'onChangeToken'? Is there more information than just "doesn't always work perfectly"? What token has to change in order for the event to fire? Is it the token that was current when the [frame:] call was made? What is it that makes it "not perfect"? It seems like this is the functionality people might be searching for to handle manual or automated updates, so what are the deficiencies, and when--if ever--CAN we rely on this event? Is it so poorly implemented and/or badly understood that we should just ignore its existence entirely?
"He knows not how to know who knows not also how to un-know." --Sir Richard Burton

User avatar
Rumble
Deity
Posts: 6235
Joined: Tue Jul 01, 2008 7:48 pm

Re: Are you aware of this: onChangeSelection

Post by Rumble »

prestidigitator wrote:So it seems pretty obvious when 'onChangeImpersonated' and 'onChangeSelection' fire, but what about 'onChangeToken'? Is there more information than just "doesn't always work perfectly"? What token has to change in order for the event to fire? Is it the token that was current when the [frame:] call was made? What is it that makes it "not perfect"? It seems like this is the functionality people might be searching for to handle manual or automated updates, so what are the deficiencies, and when--if ever--CAN we rely on this event? Is it so poorly implemented and/or badly understood that we should just ignore its existence entirely?
From Craig's comments:
The change token one is kinda tricky, it gets fired often even when it appers there has been no change to the token -- but MapTool has updated something internally that is not visible to either the user or macros -- this is why it is reccomended to have your macro update the dialog/frame when changing a token if possible, it will lead to the code being executed a lot less often
What constitutes a "change" to a token is not strictly a change in a property manipulable by macro functions or by the UI. It could - in addition to a property value change or changing it to an NPC or something - be something internal to the token's XML that is handled entirely within MapTool, and therefore I wouldn't consider it a reliable means to update a frame or dialog. Now, such an internal change may be irrelevant to any value important to the user, meaning that the macro being called by onChangeToken is run for no particular reason, but doesn't fail.

In all cases, what constitutes an event intuitively might not be the same way internally (hence why "onChangeSelection" may fire anywhere between 1 to 4 times every time you select a token). I would expect that onChangeToken probably works as reliably as the others, but you can't predict how many times it will fire, and it may fire when you haven't done anything yourself to change the token (but MapTool has made a modification).

Automatic updating is trivially handled via macro anyway; an explicit call to the frame-generating macro does the trick as easily as a callback.


Edit: Some specifics

I put together a very small campaign file that tests what might fire onChangeToken.

First off, I get a null pointer exception thrown every time I try it - something in the code is having some troubles. However, the events still fire (and the testing frame still does the trick).

So:
Moving a token fires the event twice.
Opening the Edit Token dialog (whether you change anything or not) fires the event twice
Running a macro that changes token properties fires the event twice (including things like the special token.whatever variables, it seems)
Changing a token's type (from NPC to PC) fires an additional change event on top of any property change events being fired
Setting a state or clearing it via right-click fires the event once
changing size fires the event once
Adding a light source fires the event once
Initiative actions have no effect on onChangeToken
Flipping a token horizontally or vertically seems to throw MapTool into and endless loop of onChangeToken events
Halo changes fire the event once
Snap to grid changes fire the event once

There are probably others I couldn't think of, but I ran through the right click menu and some experimental macros. The biggest problem I had was that every onChangeToken event also triggered a null pointer exception.

prestidigitator
Dragon
Posts: 317
Joined: Fri Apr 23, 2010 8:17 pm

Re: Are you aware of this: onChangeSelection

Post by prestidigitator »

Huh. Okay. I've been fooling with it a little since I posted, and it seems to be working relatively well for me for a simple frame-based character sheet that switches between view and edit states. I guess the part that saves it might be that I really expect that nothing (else) is done to the token while in the edit state. When in the view state, I really don't care if the frame is re-painted a couple times, though when multiple players are messing with things I guess it could get a bit more messy. Hmm.
"He knows not how to know who knows not also how to un-know." --Sir Richard Burton

User avatar
toyrobots
Dragon
Posts: 278
Joined: Sat Apr 12, 2008 4:17 pm

Re: Are you aware of this: onChangeSelection

Post by toyrobots »

But when I have a macro up using onChangeSelection that displays a token property (Say Current Hit Points), and I make a manual change to it, it automatically updates. It seems to relaunch the macro without having to call it again.
Is this happening for Campaign properties? Or for hidden props on the token? Details?

Cweord
Great Wyrm
Posts: 1343
Joined: Sun Aug 12, 2007 10:49 am
Location: Midsomer Norton, (Near Bath), UK
Contact:

Re: Are you aware of this: onChangeSelection

Post by Cweord »

How would I get this to run on 'Submit' from a Dialogue or Frame?

I give the PC's options for any appropriate modifiers when they make a roll, and want to use this for a GM pop up, but rather than clicking from chat, when they submit their info (and thus end that macro) one pops up for the gm to use for any hidden modifiers.

I am still getting back in to the 'MTscript' mind set having been away for a year or so
Cweord

This message has been spell checked by Freudcheck - any mistakes are purley a figment of your imagination.
-------
My Tokens Directory
http://gallery.rptools.net/v/contrib/Cw ... er_Tokens/

User avatar
Rumble
Deity
Posts: 6235
Joined: Tue Jul 01, 2008 7:48 pm

Re: Are you aware of this: onChangeSelection

Post by Rumble »

toyrobots wrote:
But when I have a macro up using onChangeSelection that displays a token property (Say Current Hit Points), and I make a manual change to it, it automatically updates. It seems to relaunch the macro without having to call it again.
Is this happening for Campaign properties? Or for hidden props on the token? Details?

Are you sure you're using "onChangeSelection" and not "onChangeToken"?
How would I get this to run on 'Submit' from a Dialogue or Frame?

I give the PC's options for any appropriate modifiers when they make a roll, and want to use this for a GM pop up, but rather than clicking from chat, when they submit their info (and thus end that macro) one pops up for the gm to use for any hidden modifiers.

I am still getting back in to the 'MTscript' mind set having been away for a year or so
onChangeSelection won't do anything like that - it simply triggers a particular macro whenever the list of selected tokens changes (in fact, it doesn't have any specific interaction with submit buttons or anything).

That's fine - except that you cannot (easily) direct a dialog to pop up on another user's PC. There is a trick involving macroLinks that can do it, but it's somewhat of a pain in the butt.

Post Reply

Return to “Macros”