Page 1 of 1

Bug? Or bad macro?

Posted: Thu Aug 12, 2010 12:46 pm
by MidnightLightning
The [wiki]evalMacro[/wiki] function does have a note in the wiki that tooltipped rolls (like [t: 1d20]) need to be presented in a [r: ] roll or { } to be formatted correctly in the output.

I ran into a problem when I wanted to create a GM-only tooltipped result. For example:

Code: Select all

[h: toolTip = evalMacro('[t:1d20+1d10]')]
**
Secret sent to GM!!** [gm: toolTip] 


This produces "**Secret sent to GM!!** « toolTip =  »1d20+1d10 = 19 + 4231d20+1d10 = 19 + 423«  »" in the chat; the HTML pulled from a message history export is:

Code: Select all

<font color="#000000"><span>**Secret sent to GM!!** &#171;</span></font><font color="blue"><span class="roll">&#160;toolTip 
= &#160;</span></font><font color="#000000"><span>&#187;&#1;1d20+1d10 = 19
+ 4&#31;23&#1;1d20+1d10 = 19 + 4&#31;23&#171;</span></font><font color="blue"><span class="roll">&#160;&#160;</span></font><font color="#000000"><span>&#187;</span></font>


I'm guessing this is the "wrong formatting" mentioned in the evalMacro page for a tooltip. So, I tried using the "unformatted" die roll parameter, because I want the DM to be able to see what the roll consists of:

Code: Select all

[h: unformatted = evalMacro('[u:1d20+1d10]')]
**
Secret sent to GM!!** [gm: unformatted] 

and I got "**Secret sent to GM!!** « unformatted =  »u1d20+1d10 = 6 + 10 = 16u1d20+1d10 = 6 + 10 = 16«  »" as a result.

Code: Select all

<font color="#000000"><span>**Secret sent to GM!!** &#171;</span></font><font color="blue"><span class="roll">&#160;unformatted 
= &#160;</span></font><font color="#000000"><span>&#187;&#1;u1d20+1d10 = 6
+ 10 = 16&#1;u1d20+1d10 = 6 + 10 = 16&#171;</span></font><font color="blue"><span class="roll">&#160;&#160;</span></font><font color="#000000"><span>&#187;</span></font>

Which is a similar error, but shouldn't really be happening, since the "unformatted" roll option should be just sending a text string, right? So is this an issue with the "gm:" roll option, or the "unformatted" option? Having the final output be a [gm,r: ] roll (combining the "gm" and "r" options) does clean up the output a little ("**Secret sent to GM!!** u1d20+1d10 = 8 + 6 = 14«  »"), but not completely.

So, does anyone have an idea on how this could be resolved so I can send the full text of a roll to the GM's using evalMacro? I have been using the evalMacro because there's more text to the GM message than just that die roll, but I'm going to split it up into multiple messages to make it work for now.

Re: Bug? Or bad macro?

Posted: Thu Aug 12, 2010 1:35 pm
by aliasmask
Hmm... never needed to use evalMacro before. Who should see what and where? Do you want to show the roller and GM the same info, but everyone else another message?
Just doing:

Code: Select all

[g: result = 1d6+1d6]
[r,s: if(isGM(),"",result)]
will show the gm only the roll result with a tooltip of each roll and the roller the result only. The GM does not get two messages in this instance if he is the roller.

edit:
You can also create your own tooltips:

Code: Select all

[H: tooltip = "<html>Tool Tip Text</html>"]
[H: output = strformat("<span title='%{tooltip}'>Text shown in chat</span>")]
[R: output]
Use of [wroll]G[/wroll], [wroll]S[/wroll] and [wroll]W[/wroll] can send whatever info you like to individual players.

Here's a code segment I use for sending a detailed report to the owner and gm and basic info to everyone else. Since there is no way a player in a macro can get the gm name(s). I actually store that name in a variable when the campaign loads.

Code: Select all

...
[
H: '<!-- Combine detailed and basic tooltips -->' ]
[
H: tHead = json.append("",'<span title="<html><table>')]
[
H, if(playerShow == 2): tHead = json.append(tHead,'<tr bgcolor=#FFA07A><td colspan=2 align=center><b>Player Detailed Report</b></td></tr>')]
[
H: tFoot = json.append("",'</table></html>">',output,"</span>")]
[
H: outputDetailed = json.merge(tHead,oTooltip1,oTooltip2,oTooltip3,tFoot)]
[
H: outputDetailed = json.toList(outputDetailed,"")]
[
H: outputBasic = json.merge(tHead,oTooltip1,tFoot)]
[
H: outputBasic = json.toList(outputBasic,"")]
[
H: '<!-- Display output to each player based on ownership -->' ]
[
H: tGM = getLibProperty("gmNames")]
[
H: tPlayers = getAllPlayerNames()]
[
H, if(isOwnedByAll()): tOwners = tPlayers; tOwners = getOwners()]
[
H, if(json.isEmpty(tOwners)): tOwners = tGM; tOwners = json.union(json.fromList(tOwners),tGM)]
[
H: tPlayers = json.fromList(tPlayers)]
[
H: tPlayers = json.difference(tPlayers,tOwners)]
[
H, if(!token.visible): playerShow = 0]
[
R,W(tOwners): outputDetailed]
[
R, if(playerShow > 0 && !json.isEmpty(tPlayers) && !(HPtype == 4 && playerShow == 1)), code: {
   [R,W(tPlayers): if(playerShow == 2,outputDetailed,outputBasic)]
};{}]
...
 

Re: Bug? Or bad macro?

Posted: Thu Aug 12, 2010 1:57 pm
by wolph42
I can relate to that (not to the bug but to the eval). I have a huge json object containing a 3-dimensional table with critical hits. Most is text output but sometimes some rolls need to be made, so I put the result of the table in an eval function. I have no problems though...

here two example results:

Code: Select all

[r:evalmacro(decode("2 The blast of energy dazzles the target, leaving him <b>blinded for 1 Round[h:newState(%22Blinded%22,1)]</b>."))]
[r:evalmacro(decode("4 The energy ripples all over the character, scorching his body and inflicting <b>[r:Fat=1d10] level(s) of Fatigue. [r:setFatigue(Fat)]</b>"))]

Re: Bug? Or bad macro?

Posted: Thu Aug 12, 2010 2:45 pm
by biodude
I don't know if it's a bug, but it might easier to construct your tooltip manually (using the title attribute of a span tag: see alisamask's post), than trying to figure out formatting of nested MapTool roll options, which can get messy, as you have discovered.

I think the note you refer to regarding displaying tooltip rolls in the macroString passed to [wfunc]evalMacro[/wfunc] means that to display the result, you must use [r: ] or {}. Could it mean you need to do this?

Code: Select all

[h: toolTip = evalMacro('[t:1d20+1d10]')]
**Secret sent to GM!!** [r, gm: toolTip]
<!-- OR -->
[h: toolTip = evalMacro('[t:1d20+1d10]')]
**Secret sent to GM!!** [GM, CODE:{ [R: toolTip] }]


I also wonder if changing the option to "Use Tooltips for Inline Rolls" in the preferences might affect the output you get from [wfunc]evalMacro[/wfunc]?