Tooltip problem

These are tools and utilities that make it easier to run games. This includes Lib: macro tokens dropped into MapTool to manage the game, a conversion file for CharacterTool to allow use in MapTool, or just about anything else you can think of -- except graphics with macros and anything specific to a particular campaign framework. Those are already covered by the Tilesets subforum and the Links and External Resources forum.

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

qschilling
Kobold
Posts: 9
Joined: Tue Oct 26, 2010 8:28 am

Re: Tooltip problem

Post by qschilling »

I copied and pasted the macro code from above into a new macro. (and a separate one for oncampaignload). Guesswork I know...

User avatar
CoveredInFish
Demigod
Posts: 3104
Joined: Mon Jun 29, 2009 10:37 am
Location: Germany
Contact:

Re: Tooltip problem

Post by CoveredInFish »

Okay. I guess - if you mention onCampaignLoad - you figured it out how to set up the lib:token and defineFunction stuff to make it work.

So now .. what does this function. And how do you use it.

It can sum up a number of name/value pairs like dice rolls and modifiers and display the sum with a detailed tabular tooltip.
It can as well check this versus a DC or target number and show miss or hit.

How do you use it. Lets say you made it so that you can use the UDF FormatTooltip(). This function expects a json object containing these name/value pairs. If this might sound complicated, it actually isnt.

Code: Select all

[h: param = json.set("", "dice roll", 1d20, "bonus 1", 2, "bonus 2", 3)]

<!-- standard usage -->
std: [r: FormatTooltip( param )]
<br>
<!-- verbose usage -->
verbose: [r: FormatTooltip( param, 0 )]
<br>
<!-- dc usage -->
dc: [r: FormatTooltip( param, 1, 15 )]
 
Lookup the wiki for Wiki: json.set(). Note that in this context you can use "" as a "empty" json object.

I hope this somehow explains it...

Ditto
Giant
Posts: 179
Joined: Thu Jul 28, 2011 1:06 pm

Re: Tooltip problem

Post by Ditto »

Hey, stumbled across this ... wow .. neat .. awesome ... I've grabbed this code, and done some "minor" tweaking of the formatting (ie I didn't want Verdana font and italics ... just plain text, thanks ..) Thank you so much for this .. it's great!! (with 1 minor issue :) )

In any case, got the FormatToolTip function defined, and working ...

So in nutshell, (D&D 4e, btw)
- I use SelectedNames() to grab selected targets.
- I loop through each selected target.
- I calc the attack mods, and send the json dump to FormatToolTip to display the result.
- end loop
- display damage.

If I choose only 1 target, as I say, it works fine ... more than 1? Stack overflow.

I'm loathe to just (blindly) increase the stack ... are these html "fancy" solutions, that hard on the stack? or am I just chewing up the stack elsewhere?

FYI: Without the FormatTooltip, I can deal with 8+ targets easy in that loop, no stack issues. This is why I believe it's the extra work of the tooltip function ...

Has anyone else had any issues with this particular UDF ? Or is there a way around it?

My Stack size is currently 1M.

I tried increasing to 2M .. just for testing ... and using the FormatToolTip, it allowed me to get up to 4 targets, but choked on 5 ...

Any suggestions?
Thanks!

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Tooltip problem

Post by wolph42 »

I've had the same problem. This has been thoroughly discussed on this forum. It basically means that you macro is too big. There is a wiki entry where the conclusions of this discussion are mentioned. I suggest you read it. Though if IIRC what you can do is have build a small macro that calls the macro that you now use. Send the resulting chat text output to that macro and have that macro put it in the chat.

Ditto
Giant
Posts: 179
Joined: Thu Jul 28, 2011 1:06 pm

Re: Tooltip problem

Post by Ditto »

wolph42 wrote:I've had the same problem. This has been thoroughly discussed on this forum. It basically means that you macro is too big. There is a wiki entry where the conclusions of this discussion are mentioned. I suggest you read it. Though if IIRC what you can do is have build a small macro that calls the macro that you now use. Send the resulting chat text output to that macro and have that macro put it in the chat.
If you're referring to this wiki entry: http://lmwcs.com/rptools/wiki/Stack_Size
yeah, I read it a while back ...

What you mention, is essentially what's already happening ... (I think?) .. that UDF is just setting up the URL, my main routine is dumping output to the chat ..

Is this specific tooltip that large? I didn't think it was? I'll try trimming it, in any case ....

Thanks!

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Tooltip problem

Post by wolph42 »

Im not sure we're understanding eachother correctly. Maybe we do maybe not: what I mean is that your main routine should accumulate all text2chat into a variable e.g. txt2chat and end the routine with:
[r:txt2chat]
Then another routine (lets call it output() ) should call the main routine e.g. [r:mainRoutine()]. This should (most likely) solve the stack problem.
If you're doing that already, than the main routine needs to be split up in smaller macros. Stack overflow basically boils down to: your macro is too big. And e.g loops only make m bigger.

User avatar
jfrazierjr
Deity
Posts: 5176
Joined: Tue Sep 11, 2007 7:31 pm

Re: Tooltip problem

Post by jfrazierjr »

Also.. using strFormat() will help quite a bit for "repeated" sections(such as TR/TD combinations) as it makes your code a lot smaller and thus is much easier on the stack.
I save all my Campaign Files to DropBox. Not only can I access a campaign file from pretty much any OS that will run Maptool(Win,OSX, linux), but each file is versioned, so if something goes crazy wild, I can always roll back to a previous version of the same file.

Get your Dropbox 2GB via my referral link, and as a bonus, I get an extra 250 MB of space. Even if you don't don't use my link, I still enthusiastically recommend Dropbox..

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

Re: Tooltip problem

Post by aliasmask »

From my experience, it's not so much too big of macros but too long of strings with multiple levels of string manipulating functions. So, be aware of the strformat, lower, replace and stuff like that.

As for stack size, I've been using 2M for almost 2 years without the need to increase it. I've only run in to a stack size problem once with my code and as mentioned above, I just split one line in to 2 lines pulling out a lower function and fixed my problem. But even then, I was dealing with a particularly large string.

Ditto
Giant
Posts: 179
Joined: Thu Jul 28, 2011 1:06 pm

Re: Tooltip problem

Post by Ditto »

ah, ok, I think I understand what you're saying ... let me play with this a bit more ..

my main routine is spitting stuff out as it goes .. so that might be the issue.

Question though ... (perhaps I'll answer this on my own as I work on it, but), how do standard tooltips work when you're stuffing everything into a single string, and then dumping it via [r: string] ??
No tooltips?

User avatar
jfrazierjr
Deity
Posts: 5176
Joined: Tue Sep 11, 2007 7:31 pm

Re: Tooltip problem

Post by jfrazierjr »

Ditto wrote:ah, ok, I think I understand what you're saying ... let me play with this a bit more ..

my main routine is spitting stuff out as it goes .. so that might be the issue.

Question though ... (perhaps I'll answer this on my own as I work on it, but), how do standard tooltips work when you're stuffing everything into a single string, and then dumping it via [r: string] ??
No tooltips?
Google HTML Title attribute on Div
I save all my Campaign Files to DropBox. Not only can I access a campaign file from pretty much any OS that will run Maptool(Win,OSX, linux), but each file is versioned, so if something goes crazy wild, I can always roll back to a previous version of the same file.

Get your Dropbox 2GB via my referral link, and as a bonus, I get an extra 250 MB of space. Even if you don't don't use my link, I still enthusiastically recommend Dropbox..

Ditto
Giant
Posts: 179
Joined: Thu Jul 28, 2011 1:06 pm

Re: Tooltip problem

Post by Ditto »

Ok .. sorry, I'm really trying to understand this, but I'm struggling.

Ok, so my original code looked something like this: (this is just a small snippet, so as not to overwhelm ...)

Code: Select all

[h: thisPower = "Testing" ]
[h: pAction = "Standard" ]
[h: pVS = "AC" ]

[h: AttMod = 5 ]
[h: AttMod2 = 2 ]
[h: Misc = 1 ]

[h: targetlist = getSelectedNames()]
[h: abort(length(targetlist))]

<table border='0'>
   <tr bgcolor='#004F00'>  <!-- at-will -->
      <table width='100%'>
         <tr>
            <td style='padding:0px 5px;'>
               <span style='color:white'><b>[r:thisPower] </b></font>
            </td>
            <td style='padding:0px 5px;' align=right>
               <span style='color:white'>Action Type: [r:pAction]</font>
            </td>
         </tr>
      </table>
   </tr>
   <tr>
      <td>
         [r,foreach(target, targetlist, '<br>'),CODE:
         {
            [h: AtkRoll=1d20]
            <b>Attack ([r:target])</b>: [t:AtkRoll+AttMod+AttMod2+Misc] vs. [r:pVS]
         }]
      </td>
   </tr>
</table>

Now, this works, and later on in the loop, I can handle 8+ targets fine, with only 1M of stack size ... no sweat.

Ok, so then I add the FormatToolTip ...

Code: Select all

[h: thisPower = "Testing" ]
[h: pAction = "Standard" ]
[h: pVS = "AC" ]

[h: AttMod = 5 ]
[h: AttMod2 = 2 ]
[h: Misc = 1 ]

[h: targetlist = getSelectedNames()]
[h: abort(length(targetlist))]

<table border='0'>
   <tr bgcolor='#004F00'>  <!-- at-will -->
      <table width='100%'>
         <tr>
            <td style='padding:0px 5px;'>
               <span style='color:white'><b>[r:thisPower] </b></font>
            </td>
            <td style='padding:0px 5px;' align=right>
               <span style='color:white'>Action Type: [r:pAction]</font>
            </td>
         </tr>
      </table>
   </tr>
   <tr>
      <td>
         [r,foreach(target, targetlist, '<br>'),CODE:
         {
            [h: AtkRoll=1d20]
            [h: RollParams = json.set("", "Attack Roll", AtkRoll, "Modifier 1", AttMod, "Modifier 2", AttMod2, "Modifier 3", Misc)]

            <b>Attack ([r:target])</b>: [r: f_FormatToolTip ( RollParams )] vs. [r: pVS]

         }]
      </td>
   </tr>
</table>

Only change was to add the tool tip .. and bam .. suddenly it can't handle more than 1 or 2 targets ... ??
Ok .. so suggestions here, say build a string, and use strformat ... ok.

Code: Select all

[h: thisPower = "Testing" ]
[h: pAction = "Standard" ]
[h: pVS = "AC" ]

[h: AttMod = 5 ]
[h: AttMod2 = 2 ]
[h: Misc = 1 ]

[h: targetlist = getSelectedNames()]
[h: abort(length(targetlist))]

[h: txt2chat = "
<table border='0'>
   <tr bgcolor='#004F00'>  <!-- at-will -->
      <table width='100%'>"]
      
[h: txt2chat = txt2chat + strformat("         <tr>
            <td style='padding:0px 5px;'>
               <span style='color:white'><b> %s </b></font>", thisPower)]
[h: txt2chat = txt2chat + strformat("            </td>
            <td style='padding:0px 5px;' align=right>
               <span style='color:white'>Action Type: %s </font>", pAction)]
[h: txt2chat = txt2chat + "            </td>
         </tr>
      </table>
   </tr>
   <tr>
      <td>"]
         [r,foreach(target, targetlist, '<br>'),CODE:
         {
            [h: AtkRoll=1d20]
            [h: RollParams = json.set("", "Attack Roll", AtkRoll, "Modifier 1", AttMod, "Modifier 2", AttMod2, "Modifier 3", Misc)]

[h: txt2chat = txt2chat + strformat("<b>Attack ( %s )</b>: %s vs. %s <br>", target, f_FormatToolTip ( RollParams ), pVS)]

         }]
[h: txt2chat = txt2chat + "  </td>
   </tr>
</table>", 1d20)]

[r: txt2chat ]
And although this still works, it still bombs after only a couple targets.

Ok, so 1 last thing I saw mentioned ...
I should call another routine to build this string ... then call yet another to display it ...

I'm struggling with figuring out how to pull that off, as for now, I'm building the above macro dynamically from another "Make power" macro ...
If I have to create 2 or 3 macros for each power, that's going to be a crazy amount of clutter!!

Ok, so I know I'm still doing something wrong, but for the life of me, I just can't seem to wrap my head around this ...
Any advice would be appreciated ...

Thanks!

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Tooltip problem

Post by wolph42 »

If its difficult Try to defer the output to another macro. So create the txt2Chat var and give that as an argument to erm forgot the name... Search the wiki for 'defer'. Should explain it.

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

Re: Tooltip problem

Post by aliasmask »

Ditto wrote:Only change was to add the tool tip .. and bam .. suddenly it can't handle more than 1 or 2 targets ... ??
Ok .. so suggestions here, say build a string, and use strformat ... ok.
Does your macro have "Apply to Selected Tokens" because the code goes through the Selected tokens already. This is a common mistake and will cause problems when selecting more than 1 token. Basically, the work load is geometric because you're processing all the tokens on each token.

Ditto
Giant
Posts: 179
Joined: Thu Jul 28, 2011 1:06 pm

Re: Tooltip problem

Post by Ditto »

wolph42 wrote:If its difficult Try to defer the output to another macro. So create the txt2Chat var and give that as an argument to erm forgot the name... Search the wiki for 'defer'. Should explain it.
execLink() ?? Hmm, might be a thought .. I'll play with that .. thanks!
aliasmask wrote: Does your macro have "Apply to Selected Tokens" because the code goes through the Selected tokens already.
No, Apply to Selected is not checked ...
I have some macros with it, and understand that feature now .. but yeah, fair question :)

I'm going to try restructuring it a bit, and maybe try that execLink() mentioned.

Oh yeah, thought of 1 more question ...

With this format tooltip, essentially, you mimic/expand on the [t: feature ... what about if you only want to show the tool tip to the GM? ie [t,gt: ??
What would have to change to do that?

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

Re: Tooltip problem

Post by aliasmask »

Ditto wrote:With this format tooltip, essentially, you mimic/expand on the [t: feature ... what about if you only want to show the tool tip to the GM? ie [t,gt: ??
What would have to change to do that?
Yeah, I do this in my framework. You basically have 2 different outputs. This is one reason why it's good to put output in to a variable. The tricky part is determining who the GM is from a player's perspective. One solution is to write to a property on a lib token during onCampaignLoad. Since, this is not supported, the developers don't recommend this. One reason is when loading the campaign on a map that doesn't have your lib (like when you save on a different map then reload) then the lib token is duplicated. There is a map switching trick that can be done (getcurrent map, switch to lib map, write property, switch back to current map). The map switching doesn't really affect load time much and I find it worth it to keep track of gm names in a property for just this reason (separate outputs).

Post Reply

Return to “Drop-In Macro Resources”