Html and display roll options

Thoughts, Help, Feature Requests, Bug Reports, Developing code for...

Moderators: dorpond, trevor, Azhrei

Forum rules
PLEASE don't post images of your entire desktop, attach entire campaign files when only a single file is needed, or generally act in some other anti-social behavior. :)
Post Reply
bobifle
Giant
Posts: 219
Joined: Thu Oct 19, 2017 12:36 pm

Html and display roll options

Post by bobifle »

I apologize for the cross post forum/discord. I didn't get answers from the discord, the discord ppl are probably tired of answering my constant questions, I won't blame them 8)

I'm trying to send my token's html macros only to the GM, because it's NPC related info. How do I do that ?

I've tried so far:

Code: Select all

[gm, code: {<br> this is a test <br>}]
[gm: 1d20+5]
this first item is broadcasted to players, the second item is sent only to the GM.

Second question is there a way to propagate roll options to lib macros ? When calling a lib macro

Code: Select all

[s, macro("Init@Lib:Addon5e"):0]
is there a way that the Init macro uses the 's' roll options for its display ?

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

Re: Html and display roll options

Post by aliasmask »

If you're using my starter lib token, I have a built in output function xx.lib.output.basic(chatText,targets,token) where targets can be

Code: Select all

      * all - all players (keywords are case sensitive) 
      * owner - anyone who owns the token. token must be valid and on current map
      * other - anyone who doesn't own token. token must be valid and on current map
      * gm - only gm players
      * -gm - anyone but the gm
      * self - only displayed to self
      * -self - display to all other players
and any combination of the above including player names. "token" is the impersonated token. It looks the same as the normal chat text output except you can mouse over the token to get the player name who posted it. Just in case of multiple owners or duplicate images/token names.

BTW. [gm, code: {...}] should display only for gm as well. code, although valid is a bit redundant. It's used as a wrapper for other roll options. Sort of like extra ()'s. I would avoid using outside of if(), switch() and loop roll options.

#2 - "propagate roll options to lib macros" I'm failing to decipher your meaning with this. Do you mean to rewrite a roll option like with Wiki: oldFunction()? If yes, then no.

#3 - Never tried it, but seem like it should work. I'm not sure if macro() obeys other print roll options mostly because I almost never use macro() (I prefer UDFs). Since you're asking, I take it that it doesn't work. You can convert to an UDF and then it will definitely work.

Code: Select all

<!-- assuming my lib token -->
[S,R: xx.lib.Addon5e(0)]
<!-- or -->
[H: xx.lib.output.basic(xx.lib.Addon5e(0),"self",currentToken()]

bobifle
Giant
Posts: 219
Joined: Thu Oct 19, 2017 12:36 pm

Re: Html and display roll options

Post by bobifle »

BTW. [gm, code: {...}] should display only for gm as well
It does not, is this a bug ?

Code: Select all

[gm, code: {<br>foo<br>}]
will be sent to players.

I've looked into your starter pack and I think I need to learn how to use the broadcast function properly...

For my roll option propagation stuff, consider the macro Foo of Lib:Bar token:

Code: Select all

[r: <br>Foo<br>>]
Is there a way so that

Code: Select all

[s, macro("Foo@Lib:Bar"):0]
prints 'Foo' only on the executer chat window

Code: Select all

[gm, macro("Foo@Lib:Bar"):0]
prints 'Foo' only on the GM chat window

Phergus
Deity
Posts: 7132
Joined: Fri May 12, 2006 8:56 pm
Location: Middle of Nowhere, NM
Contact:

Re: Html and display roll options

Post by Phergus »

bobifle wrote:
Fri Nov 23, 2018 8:36 am
BTW. [gm, code: {...}] should display only for gm as well
It does not, is this a bug ?

Code: Select all

[gm, code: {<br>foo<br>}]
will be sent to players.
It's because you have the code {} block. Try this:

Code: Select all

[g, code: {
    Everybody sees this.
    [g: foo = "<br/>GM only text"]
    [s: foo = "<br/>Only myself"]
    [w("Bob"): foo = "<br/>Only Bob sees this"]
}]
Same thing will happen to you if you have an if or foreach code block.

User avatar
Full Bleed
Demigod
Posts: 4736
Joined: Sun Feb 25, 2007 11:53 am
Location: FL

Re: Html and display roll options

Post by Full Bleed »

What is the point of a non-conditional code block?
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

Phergus
Deity
Posts: 7132
Joined: Fri May 12, 2006 8:56 pm
Location: Middle of Nowhere, NM
Contact:

Re: Html and display roll options

Post by Phergus »

Beats me.

bobifle
Giant
Posts: 219
Joined: Thu Oct 19, 2017 12:36 pm

Re: Html and display roll options

Post by bobifle »

This is the kind of nonsense comming up when I try to make things work, I was trying to apply a roll option to a whole block.

On the other side, you are probably familiar with MT for a long time and you may have forget how MT blocks and rolls options can be confusing sometimes:

Code: Select all

[h, code: {this is a Hidden  test }]
[gm, code: {this is a GM test }]
[s, code: {this is a Self test }]
This first (hidden) behaves as I would have expected: nothing is displayed. I conclued that the roll option "h" was applicable to the whole block.

The second and third item (gm and self) print both their text to the GM and player chat, that's not supposed to happen with gm and s options.

I'm very confused.

Phergus
Deity
Posts: 7132
Joined: Fri May 12, 2006 8:56 pm
Location: Middle of Nowhere, NM
Contact:

Re: Html and display roll options

Post by Phergus »

It probably is a bug that has never been seen because nobody uses the code option like that. A perfectly valid thing to do and might be handy if it worked as you expected it to.

I'd say file a bug report on Github with the info you just shared.

User avatar
Full Bleed
Demigod
Posts: 4736
Joined: Sun Feb 25, 2007 11:53 am
Location: FL

Re: Html and display roll options

Post by Full Bleed »

Phergus wrote:
Fri Nov 23, 2018 6:05 pm
It probably is a bug that has never been seen because nobody uses the code option like that.
This. I've never seen someone try. ;)

The code_(roll_option) wiki states:
The CODE option is used in conjunction with looping / branching options to execute multiple statements within a single "block" of a loop or branch, allowing the creation of more complex loops and branches.
I agree that there is an inconsistency with how it interacts with various roll options... but what's the bug? That it heeds the HIDDEN roll option, that it doesn't heed the GM and SELF options, or that it doesn't throw an error when it's used without a condition?


As an aside, I think that most macro writers steer new users away from complex roll option output and toward broadcast when they see them bumping into the basic roll option limitations and quirks.
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

bobifle
Giant
Posts: 219
Joined: Thu Oct 19, 2017 12:36 pm

Re: Html and display roll options

Post by bobifle »

Using Aliasmask functions, I'm able to send html whereever I want. Nice.

Obviously, I hit another wall...

Code: Select all

[h: html = "<br>Foo<br>"]
is easy.

But how to you set the html variable value with the following html, :

Code: Select all

<div style="background-color: #444444; color: #FFFFFF; padding-top:2px; padding-bottom:5px; padding-left:8px; padding-right:8px;">
	Saving Throws:
	<div style="background-color:#FFFFFF; color: #000000; padding:2px;">
		[r, foreach(Attribute, "['Wisdom', 'Dexterity']"), code: {
			[h: attr = substring(Attribute, 0, 3)]
			[h: modifier =  json.get("{'foo':5}", "foo")]
			[attr]: [1d20 + modifier]
		}]
	</div>
</div>
I slightly modified the html code so it's "self executable", if you want to try it. The html by itself displays correctly. But I don't know how to put the result into a variable. 2 issues i think:

1/ escaping quotes from the div style
2/ handle the MT code right in the middle.

I was looking at evalmacro to see if it can help, but I'm stuck with the quotes anyway.

Edit: it seems I can replace div dquotes " by quotes ', which reduce the problem to:

Code: Select all

[r: html ="
<div style='background-color: #444444; color: #FFFFFF; padding-top:2px; padding-bottom:5px; padding-left:8px; padding-right:8px;'>
		[r: json.get("{'Foo': 5}", "Foo")]
</div>
"]
Edit2 :
I may have figured it out, I have to build the html step by step, splitting "html" part and MT code:

Code: Select all

[h: html ="
<div style='background-color: #444444; color: #FFFFFF; padding-top:2px; padding-bottom:5px; padding-left:8px; padding-right:8px;'>
"]
[h: html = html + json.get("{'Foo': 5}", "Foo")]
[h: html = html + "</div>"]
[r: html]
Is this the only/appropriate way ?

Phergus
Deity
Posts: 7132
Joined: Fri May 12, 2006 8:56 pm
Location: Middle of Nowhere, NM
Contact:

Re: Html and display roll options

Post by Phergus »

That's the way I do it in general. Build up the output string in pieces.

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

Re: Html and display roll options

Post by aliasmask »

I don't recommend building jsons manually

Code: Select all

[r, foreach(Attribute, "['Wisdom', 'Dexterity']"), code: {
I would just use the functions

Code: Select all

[r, foreach(Attribute,json.append("","Wisdom", "Dexterity")), code: {
I often build my output and put it in to a json array. Then I put it in to a normal string with this conversion.

Code: Select all

[H: output = json.toList(outputArray,"")]
I try to keep all my html standard like style="..." rather than using single quotes. Single Quote output that's just text and not script I use the html entity. I can then surround my html with single quotes.

I also use %{varname} in the text to plug in dynamic values and then use strformat to convert. Here are some output creation examples.

Code: Select all

[H: card.template = '<table width="300px" class="tableOut">
<table width="100%" class="tableIn">
   <tr valign="top"><td class="col1">Race:</td><td class="col2"><b>%{raceLine}</b></td></tr>
   <tr valign="top"><td class="col1">Summary:</td><td class="col2"><i>%{var.summary}</i></td></tr>
   
   <tr valign="top"><td colspan=2 class="bar">&nbsp;</td></tr>
   
   <tr valign="top"><td class="col1">Ability:</td><td class="col2">%{var.abilityadjustments}</td></tr>
   <tr valign="top"><td class="col1">HP:</td><td class="col2">%{var.hitpoints}</td></tr>
   <tr valign="top"><td class="col1">Size:</td><td class="col2">%{var.size}</td></tr>
   <tr valign="top"><td class="col1">Vision:</td><td class="col2">%{var.vision}</td></tr>
   <tr valign="top"><td class="col1">Move:</td><td class="col2">%{var.move}</td></tr>
   
   <tr valign="top"><td colspan=2 class="bar">&nbsp;</td></tr>
   
   <tr valign="top"><td colspan=2 class="spancol">RACIAL TRAITS</td></tr>
   <tr valign="top"><td colspan=2 class="indent">%{traitList}</td></tr>
</table></table>']

Btw, I wrote a macro to convert a json object in to local variables. Wish this was in MT normally like the varsFromStrProp, except for jsons.

Code: Select all

@@ @json.toVars
@PROPS@ fontColor=black ; autoExecute=true ; fontSize=11pt ; sortBy= ; color=pink ; playerEditable=true ; applyToSelected=false ; group=Utility ; tooltip= ; minWidth=94 ; 
<!-- json.toVars(obj,prefix): varList
   obj - variable is a json object
   varList - A json object of prop names to original key word.
   
   This function defines the keys of a json object as local variables with the format prefix ("var") + "." + lowercase keyword with no spaces.
 -->

[H: sub.obj = arg(0)]
[H, if(argCount() >= 2): sub.prefix = arg(1); sub.prefix = "var"]
[H, if(json.isEmpty(sub.prefix)): sub.prefix = "var"]
[H: sub.varList = "{}"]

[H, if(json.type(sub.obj) == "OBJECT"), code: {
   [H, foreach(varName,sub.obj), code: {
      [H: sub.varName = keyToVar(varName,sub.prefix)]
      [H: sub.varList = json.set(sub.varList,sub.varName,varName)]
      [H: set(sub.varName,json.get(sub.obj,varName))]
   }]
}]

[H: macro.return = sub.varList]

!!
I plan to write the other function that takes the local vars and puts them back to the original object structure using the sub.varList object.

oh, forgot the prop name clean up.

Code: Select all

@@ @keyToVar
@PROPS@ fontColor=black ; autoExecute=true ; fontSize=11pt ; sortBy= ; color=pink ; playerEditable=true ; applyToSelected=false ; group=Utility ; tooltip= ; minWidth=94 ; 
<!-- keyToVar(keyword,prefix): propName

   keyword - any string typically found as a key to json object
   prefix - default "var." adds on to keyword to make prop name.
   propName - final convertion of keyword to a valid prop name format.
-->

[H, if(argCount() >= 2): macro.return = arg(1) + "." + replace(lower(arg(0)),"[^a-zA-Z0-9_.]",""); macro.return = replace(lower(arg(0)),"[^a-zA-Z0-9_.]","")]

!!

User avatar
Full Bleed
Demigod
Posts: 4736
Joined: Sun Feb 25, 2007 11:53 am
Location: FL

Re: Html and display roll options

Post by Full Bleed »

Alias, good stuff.

You should try to put all of your output focused functions and methodology into some kind of drop-in.
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

Post Reply

Return to “MapTool”