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
CoveredInFish
Demigod
Posts: 3104
Joined: Mon Jun 29, 2009 10:37 am
Location: Germany
Contact:

Are you aware of this: onChangeSelection

Post by CoveredInFish »

I just found some nice jewel hidden deep in the googleDocs-doc for maptool (linked from some fixed thread...). I wasnt aware of it and I would wonder if it would be common knowledge.

Frames and dialogs can call macros on some events. :shock: To do this place a <link> in the html-header of your frame/dialog-content. There are three events, on impersonation, on selection and on changes made on a token. The latter is said to work not perfectly.

Code: Select all

<link rel='onChangeImpersonated' type='macro' href='macroLink'> 
<link rel='onChangeSelection' type='macro' href='macroLink'>
<link rel='onChangeToken' type='macro' href='macroLink'>
I have to play around with these more, but i build a simple example: frame showing the actual selected tokens and some information (in the sample its only pc/npc-status).
Example
place these two macros on a lib:token. Click "openFrame". Select some macros.

openFrame

Code: Select all

[frame("showSelected"): {
[r, macro("frameContent@lib:token"):""]
}]
 
frameContent

Code: Select all

<html>
<head>
    <link rel='onChangeSelection' type='macro' href='[r:macroLinkText("open frame@lib:token")]'> 
</head>
<body>
    [h: selection = getSelected()]
    [h: odd = 1]
    <table width="100%">
    [r, foreach( id, selection,"" ), code: {
        <tr style='background-color:[r:if(odd, "#ffffff;","#aaffaa;")]'>
            <td><img src='[r, token(id): getTokenImage(50)]'></td>
            <td><b>[r:getName(id)]</b></td>
            <td>[r: if(isPC(id), "PC", "NPC")]</td>
        </tr>
        [h: odd = if(odd, 0, 1)]
    }]
    </table>
</body>
</html>
 

Craig
Great Wyrm
Posts: 2107
Joined: Sun Jun 22, 2008 7:53 pm
Location: Melbourne, Australia

Re: Are you aware of this: onChangeSelection

Post by Craig »

To answer your question
yes I am aware of this :)

Some things to keep in mind when using these
The impersonation event may be called when you run a macro with run on selected tokens checked and then again at the end when it reimpersonates the original token

The selection one may be fired by some token changes if they are made to a selected token, even if this occurs on another client. When you select a token it maybe fired twice, once for the selection change associated with the deselection of the previously selected token, and once for the new selection, under certain circumstances you could get it fired a third time (1 for deselect, 2 for new token)

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

I have purposefully used the words can or may above as you should not rely on these side effects as they don't happen in all cases but you should be aware that they can happen so you write your macros accordingly

The othe thing you need to know is, you should not modify any tokens in macros fired off from these events, depending on what you try to do you can cause yourslef quite a lot of problems.


User avatar
plothos
Great Wyrm
Posts: 1890
Joined: Sat Jun 21, 2008 1:07 am

Re: Are you aware of this: onChangeSelection

Post by plothos »

Yeah, as I recall DeviantNull uses this (the on change selection element) in his interactive character sheet.
And I purloined the technique and use it in my own. :)

Remember, if you do this, to have a check to see if the selected token has all the properties needed. In my case, I just fill the frame with "Not a character" in that event.
Drop-In Utilities:
My Spell Manager for D&D3.5 and PFRPG
My Inventory Manager for D&D and PFRPG, but more generally useable than that.
My Message Manager -- My Top-Down D&D Token Images
and my Custom Initiative & Status/Spell-Effect Tracker (work in progress, but functional).

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

Re: Are you aware of this: onChangeSelection

Post by Rumble »

I quickly fiddled with it, but couldn't get it to recognize the newly selected token (that is, when I changed selections, it threw a cloud of "Enter value for" prompts). I had configured the macroLink to send arguments and/or operate on the proper token (I think) but it was a bust.

It's not relevant to my framework (I don't use a character sheet) but it's nifty, nonetheless.

Edit - although, it would be excellent for my Dragon Age framework.
Last edited by Rumble on Wed Mar 03, 2010 11:35 am, edited 1 time in total.

User avatar
plothos
Great Wyrm
Posts: 1890
Joined: Sat Jun 21, 2008 1:07 am

Re: Are you aware of this: onChangeSelection

Post by plothos »

If I ever get my framework to a place where it's worth posting (meaning two days before never), I can show it off. If you have a multi-page sheet, you can even have it save the page when you change tokens.

Pretty sure DeviantNull does this too.
Drop-In Utilities:
My Spell Manager for D&D3.5 and PFRPG
My Inventory Manager for D&D and PFRPG, but more generally useable than that.
My Message Manager -- My Top-Down D&D Token Images
and my Custom Initiative & Status/Spell-Effect Tracker (work in progress, but functional).

User avatar
RPTroll
TheBard
Posts: 3159
Joined: Tue Mar 21, 2006 7:26 pm
Location: Austin, Tx
Contact:

Re: Are you aware of this: onChangeSelection

Post by RPTroll »

Very good information. Thanks for sharing.
ImageImage ImageImageImageImage
Support RPTools by shopping
Image
Image

User avatar
aliasmask
RPTools Team
Posts: 9023
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Are you aware of this: onChangeSelection

Post by aliasmask »

I can probably use this in my newest project because it shows the currently selected tokens, but I fear it could interfere with other stuff so I get what I have going, then dink with this later.

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

Re: Are you aware of this: onChangeSelection

Post by Rumble »

plothos wrote:If I ever get my framework to a place where it's worth posting (meaning two days before never), I can show it off. If you have a multi-page sheet, you can even have it save the page when you change tokens.

Pretty sure DeviantNull does this too.

So how do you make it recognize the change in the current token? That seems to be what's tripping me up. If I launch my character sheet (there is one in my framework, but it's not particularly dynamic - however, this could make it so), the launching token is the current token, and it stays that way.

However, if I put in the onChangeSelected event link, and I select a new token (after the initial launch), it loses all context. I've tried sending arguments via the macro link, but that doesn't work. Do I need, instead, to have a quick "getSelected()" check in the macro that deploys the sheet - like "switchToken(getSelected())" right at the beginning?

I only had a few minutes to play around with it this morning, so I didn't explore all the options.

User avatar
plothos
Great Wyrm
Posts: 1890
Joined: Sat Jun 21, 2008 1:07 am

Re: Are you aware of this: onChangeSelection

Post by plothos »

If you have the link that executes on selection change run a macroLink() with 'selected' as the target, it should detect what ever got picked up. The key of course is making sure the frame doesn't go looking for property types on the wrong tokens.

Here's a stripped down campaign file with a couple tokens on it and the character sheet macros I use atm, and a pic showing some of the displays you get just selecting different tokens with the frame open.
Attachments
Demo.jpg
Demo.jpg (124.48 KiB) Viewed 19501 times
Char Sheet Example.cmpgn
(1.01 MiB) Downloaded 359 times
Last edited by plothos on Wed Mar 03, 2010 3:34 pm, edited 2 times in total.
Drop-In Utilities:
My Spell Manager for D&D3.5 and PFRPG
My Inventory Manager for D&D and PFRPG, but more generally useable than that.
My Message Manager -- My Top-Down D&D Token Images
and my Custom Initiative & Status/Spell-Effect Tracker (work in progress, but functional).

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

Re: Are you aware of this: onChangeSelection

Post by Rumble »

plothos wrote:If you have the link that executes on selection change run a macroLink() with 'selected' as the target, it should detect what ever got picked up. The key of course is making sure the frame doesn't go looking for property types on the wrong tokens.

Here's a stripped down campaign file with a couple tokens on it and the character sheet macros I use atm.

Oh, I didn't realize "selected" was a built-in option for the macroLinks! Well, that changes EVERYTHING!

(actually, it doesn't, but it does explain whassup with my problems!)

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

Re: Are you aware of this: onChangeSelection

Post by Rumble »

Got it working; thanks!

I found out an interesting thing (I was using assert()'s to check a few things) - in my framework, the event fires four times every time you change selections.

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

Re: Are you aware of this: onChangeSelection

Post by skester »

Oh, I am so using this!

Thank you very much!

skester

Darinth
Dragon
Posts: 424
Joined: Wed Oct 21, 2009 2:52 pm

Re: Are you aware of this: onChangeSelection

Post by Darinth »

Probably not gonna play with this right now... but this has a number of potential uses. Character sheet and targeting are what come to mind first...
Loyalty is not blind, and it cannot be forced. It is a sincere bond formed out of respect and gratitude.

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

Re: Are you aware of this: onChangeSelection

Post by Rumble »

Darinth wrote:Probably not gonna play with this right now... but this has a number of potential uses. Character sheet and targeting are what come to mind first...

Targeting to some extent, although you'll need to account for multiple firings of the event (as I mentioned, it's been 3-4 firings of the event to select a token; plus, of course, the old "non-owned selection" issue is still a factor) - so however you do it, you need to run only one iteration of whatever happens next.

However, it's pretty cool. I've noticed it screwed up the CSS in one of my forms. It was a little better if I put the CSS link first, but still not perfect. Otherwise, though - really excellent for a dynamic, keeping up with your actions character sheet. A better tool for a GM than a player, almost.

Post Reply

Return to “Macros”